Welcome back! In the previous chapters, we built the Gateway (the brain) and the Control UI (the dashboard).
Now we have a system that can talk to devices, but we haven't told it what to say or do. We need a way to create complex plans for our agents. Enter OpenProse.
Writing code to coordinate multiple AI agents can be messy. Imagine trying to write a Python script that says: "Ask Agent A to write a joke, then take that joke and ask Agent B to translate it, but only if the joke is funny."
OpenProse is a custom language designed specifically for OpenClaw. It allows you to write "scripts" or "workflows" that look almost like English text. It lives in the extensions/open-prose folder.
The Central Use Case: You want to create an automated "News Team." One agent (The Researcher) finds a topic, and a second agent (The Writer) writes a paragraph about it. Instead of writing 100 lines of complex JavaScript, you want to define this relationship in just 3 lines of readable text.
To understand OpenProse, think of it as writing a script for a movie.
This is a text file where you define the story. It lists which characters (Agents) are involved and what they should say or do.
This is the translator. It reads your readable OpenProse script and turns it into ugly machine code (JSON) that the Gateway understands.
A series of steps. OpenProse ensures that Step 2 doesn't start until Step 1 is finished.
OpenProse is designed to be readable. Let's look at how to solve our "News Team" use case.
An OpenProse file usually looks like AgentName -> Instruction.
Here is an example script news_team.op:
# This is a comment
Researcher -> Find a fun fact about dolphins.
Writer -> Take the result from Researcher and write a poem.
Explanation:
To run this script, you would pass it to the OpenProse extension within your application code.
import { runOpenProse } from './extensions/open-prose/index.js';
// The script we wrote above
const myScript = `
Researcher -> Find a fun fact about dolphins.
Writer -> Write a poem about it.
`;
// Execute it!
runOpenProse(myScript);
What happens:
How does text become action? The OpenProse extension acts as a compiler. It doesn't execute the AI itself; it prepares instructions for the Gateway.
Here is what happens when you run a script.
The magic happens inside extensions/open-prose/src/. Let's look at a simplified version of the Parser.
1. The Parser (parser.js):
This function takes the text and splits it into actionable objects.
// A simplified parser function
export function parseScript(scriptText) {
// Split the file by new lines
const lines = scriptText.split('\n');
return lines.map(line => {
// Split "Agent -> Action" by the arrow
const [agent, action] = line.split('->');
return {
agentName: agent.trim(),
prompt: action.trim()
};
});
}
Explanation:
-> arrow.agentName (Who), and the right side becomes the prompt (What).2. The Execution Engine: Once we have the list of objects (steps), we need to iterate through them.
// A simplified execution loop
async function executeWorkflow(parsedSteps) {
let context = ""; // Holds the result of the previous step
for (const step of parsedSteps) {
console.log(`Calling ${step.agentName}...`);
// Combine previous context with new prompt
const fullPrompt = `${context}\n\n${step.prompt}`;
// Simulate sending to Gateway and waiting
context = await sendToGateway(step.agentName, fullPrompt);
}
}
Explanation:
context) to the current request. This gives the AI "memory" of what just happened.In this chapter, we learned about OpenProse, the scripting language of OpenClaw.
extensions/open-prose.Agent -> Action).However, for OpenProse to work, the system needs to know who "Researcher" and "Writer" actually are. Are they GPT-4? Are they a local script? To define these identities, we need to configure our system.
Generated by Code IQ