@simulacra-ai/core 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/dist/index.cjs +20 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,13 +90,29 @@ class WeatherTool {
|
|
|
90
90
|
|
|
91
91
|
The workflow engine drives the tool call loop and enables agentic behaviors. The `WorkflowManager` sits on top of the conversation object, managing workflow state and executing tools on the model's behalf, running them in parallel when possible, and feeding results back until the model produces a final response.
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
### Running a Workflow
|
|
94
|
+
|
|
95
|
+
`manager.run()` sends a prompt and returns a promise that resolves when the full workflow completes, including all tool execution rounds.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
using conversation = new Conversation(provider);
|
|
99
|
+
using manager = new WorkflowManager(conversation);
|
|
100
|
+
|
|
101
|
+
conversation.toolkit = [WeatherTool];
|
|
102
|
+
|
|
103
|
+
const result = await manager.run("What's the weather in Tokyo?");
|
|
104
|
+
// result.reason is "complete", "cancel", or "error"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
This is different from `conversation.prompt()`, which resolves after a single model response. If the model responds with tool calls, `prompt()` returns after that first response while the workflow continues executing tools in the background. `manager.run()` waits for the entire loop to finish.
|
|
108
|
+
|
|
109
|
+
### Events
|
|
110
|
+
|
|
111
|
+
The workflow manager also emits events throughout its lifecycle, making it possible to observe the full agentic loop without `run()`.
|
|
94
112
|
|
|
95
113
|
```typescript
|
|
96
|
-
// create a conversation and workflow manager
|
|
97
114
|
using manager = new WorkflowManager(conversation);
|
|
98
115
|
|
|
99
|
-
// log the final message when the workflow completes
|
|
100
116
|
manager.once("workflow_begin", (workflow) =>
|
|
101
117
|
workflow.once("workflow_end", () => {
|
|
102
118
|
console.log(conversation.messages.at(-1));
|
package/dist/index.cjs
CHANGED
|
@@ -2164,6 +2164,26 @@ var WorkflowManager = class {
|
|
|
2164
2164
|
throw new Error("invalid state");
|
|
2165
2165
|
}
|
|
2166
2166
|
}
|
|
2167
|
+
async run(input) {
|
|
2168
|
+
if (this.#state !== "idle") {
|
|
2169
|
+
throw new Error("invalid state");
|
|
2170
|
+
}
|
|
2171
|
+
const workflow_end = new Promise((resolve) => {
|
|
2172
|
+
const handler = (event) => {
|
|
2173
|
+
if (event.event_name === "workflow_end") {
|
|
2174
|
+
this.off("workflow_event", handler);
|
|
2175
|
+
resolve(event.event_args[0]);
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2178
|
+
this.on("workflow_event", handler);
|
|
2179
|
+
});
|
|
2180
|
+
if (typeof input === "string") {
|
|
2181
|
+
await this.#conversation.prompt(input);
|
|
2182
|
+
} else {
|
|
2183
|
+
await this.#conversation.send_message(input);
|
|
2184
|
+
}
|
|
2185
|
+
return workflow_end;
|
|
2186
|
+
}
|
|
2167
2187
|
#on_prompt_send = ({ message }) => {
|
|
2168
2188
|
if (this.#current_workflow) {
|
|
2169
2189
|
return;
|