You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Debugging**: Add debugging information that doesn't appear in AI conversations
741
742
-**Integration**: Store data needed for external systems or APIs
742
743
744
+
### Per‑Agent Message Scoping (Multi‑Agent in One Workflow)
745
+
746
+
Keep control state global (loading, inputDisabled, statusLine, queue, taskList). Use lightweight agent handles to scope messages and transcripts per agent within a single workflow.
747
+
748
+
```ts
749
+
const planner =actions.createAgent("Planner"); // auto‑generates UUID id
750
+
console.log(planner.id); // uuid
751
+
console.log(planner.name); // "Planner"
752
+
planner.setName("PlanBot"); // updates display name (keeps same id)
753
+
planner.say("Starting plan…");
754
+
755
+
const planResult =awaitgenerateText({
756
+
model: openai("gpt-4o"),
757
+
system: "You are the planning agent.",
758
+
messages: planner.transcript(),
759
+
tools: tools.definitions,
760
+
});
761
+
762
+
// Assistant and tool messages are tagged to this agent only
763
+
awaitplanner.handleModelResults(planResult);
764
+
765
+
// Another agent in the same workflow
766
+
const executor =actions.createAgent("Executor");
767
+
const execResult =awaitgenerateText({
768
+
model: openai("gpt-4o-mini"),
769
+
system: "You are the execution agent.",
770
+
messages: executor.transcript(),
771
+
tools: tools.definitions,
772
+
});
773
+
awaitexecutor.handleModelResults(execResult);
774
+
```
775
+
776
+
Notes:
777
+
-`actions.createAgent(name)` returns a handle with `id`, `name`, `setName`, `say`, `addMessage`, `transcript`, `handleModelResults`.
778
+
- Messages produced via these methods carry `metadata.agentId = id` and the UI prefixes messages with `[name]` (fallback to `[id]`).
779
+
- All other state (loading, inputDisabled, statusLine, queue, taskList) remains global at the workflow level.
780
+
781
+
#### Message structure and storage
782
+
783
+
- Storage model: a single workflow‑level message log (`state.messages`). There is no `agentsById` state; messages are attributed to agents via metadata and names are stored in `state.agentNames`.
784
+
- Each message can include agent attribution by id only; names are resolved at render time:
785
+
786
+
```ts
787
+
// UI-only messages or model/tool messages with optional agent attribution
- Global transcript (`state.transcript`): excludes UI messages and excludes any message with `metadata.agentId` (i.e., sub‑agents are filtered out). Use this for simple single‑agent prompts.
803
+
- Per‑agent transcript (`agent.transcript()`): includes only non‑UI messages tagged with that agent’s `id`.
804
+
- Tool execution: assistant messages and tool results produced via `agent.handleModelResults(result)` are tagged with that agent. Tool‑synthesized user messages are routed via the normal input path.
805
+
- UI display: when `metadata.agentId` is present, the terminal UI prefixes the role header with `[name]` using `state.agentNames[agentId]` (fallback to `[id]`). You can override this by providing `displayConfig.formatRoleHeader` or a custom `agentNameResolver`.
These tools are available to your agent when you pass `tools.definitions` to your model call. Consider including the brief definitions below in your system prompt so the model knows how to use them.
982
+
983
+
-**`shell`**
984
+
-**What it does**: Execute a shell/CLI command (including `git`) in a given working directory.
985
+
-**Parameters**:
986
+
-`cmd: string[]` — command and args, e.g. `["git","status"]`
987
+
-`workdir: string` — working directory
988
+
-`timeout: number` — milliseconds
989
+
990
+
-**`apply_patch`**
991
+
-**What it does**: Apply file edits via a structured `apply_patch` payload for auditable changes.
992
+
-**Parameters**:
993
+
-`cmd: string[]` — invocation and payload, e.g. `["apply_patch","*** Begin Patch\\n...\\n*** End Patch"]`
994
+
-`workdir: string` — working directory
995
+
-`timeout: number` — milliseconds
996
+
997
+
-**`user_select`** (UI mode only)
998
+
-**What it does**: Prompt the user to choose from options. The UI also includes a "None of the above (enter custom option)" choice automatically.
999
+
-**Parameters**:
1000
+
-`message: string` — text shown to the user
1001
+
-`options: string[]` — available choices
1002
+
-`defaultValue: string` — must match one of `options`; used on timeout
1003
+
1004
+
Note: In headless mode, only `shell` and `apply_patch` are available; `user_select` is not supported.
1005
+
1006
+
### Prompt guidance: include tool definitions
1007
+
1008
+
Add a succinct description of the tools and their parameter shapes in your system prompt so the model reliably uses them. For example:
1009
+
1010
+
```text
1011
+
You can use the following tools. Call them with the exact parameter shapes.
1012
+
1013
+
- shell: run terminal commands.
1014
+
Parameters: { cmd: string[]; workdir: string; timeout: number }
1015
+
1016
+
- apply_patch: make file edits using a single apply_patch payload wrapped in *** Begin Patch ... *** End Patch.
1017
+
Parameters: { cmd: string[]; workdir: string; timeout: number }
1018
+
1019
+
- user_select (UI only): ask the user to pick from options; a custom option entry is available in the UI.
0 commit comments