zeitlich 0.2.3 → 0.2.4
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/dist/index.cjs +28 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -42
- package/dist/index.js.map +1 -1
- package/dist/{workflow-D-2vp4Pq.d.cts → workflow-PjeURKw4.d.cts} +12 -29
- package/dist/{workflow-D-2vp4Pq.d.ts → workflow-PjeURKw4.d.ts} +12 -29
- package/dist/workflow.cjs +20 -31
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +1 -1
- package/dist/workflow.d.ts +1 -1
- package/dist/workflow.js +20 -31
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/activities.ts +0 -19
- package/src/lib/model-invoker.ts +7 -1
- package/src/lib/session.ts +3 -15
- package/src/lib/tool-router.ts +9 -9
- package/src/lib/types.ts +7 -5
- package/src/tools/{task → subagent}/handler.ts +18 -31
- package/src/tools/{task → subagent}/tool.ts +13 -13
- package/src/workflow.ts +2 -3
|
@@ -58,13 +58,13 @@ declare function createThreadManager(config: ThreadManagerConfig): ThreadManager
|
|
|
58
58
|
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* Creates a
|
|
61
|
+
* Creates a Subagent tool configured with the available subagents.
|
|
62
62
|
*
|
|
63
63
|
* @param subagents - Array of subagent configurations (must have at least one)
|
|
64
64
|
* @returns A tool definition with dynamic schema based on available subagents
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
67
|
-
* const
|
|
67
|
+
* const subagentTool = createSubagentTool([
|
|
68
68
|
* {
|
|
69
69
|
* name: "researcher",
|
|
70
70
|
* description: "Researches topics and gathers information",
|
|
@@ -73,7 +73,7 @@ declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThr
|
|
|
73
73
|
* },
|
|
74
74
|
* ]);
|
|
75
75
|
*/
|
|
76
|
-
declare function
|
|
76
|
+
declare function createSubagentTool<T extends SubagentConfig[]>(subagents: T): {
|
|
77
77
|
name: string;
|
|
78
78
|
description: string;
|
|
79
79
|
schema: z.ZodObject<{
|
|
@@ -83,9 +83,9 @@ declare function createTaskTool<T extends SubagentConfig[]>(subagents: T): {
|
|
|
83
83
|
}>;
|
|
84
84
|
};
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
86
|
+
* Subagent tool args type (when subagent names are not known at compile time)
|
|
87
87
|
*/
|
|
88
|
-
type
|
|
88
|
+
type SubagentArgs = {
|
|
89
89
|
subagent: string;
|
|
90
90
|
description: string;
|
|
91
91
|
prompt: string;
|
|
@@ -436,13 +436,13 @@ declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType, TCont
|
|
|
436
436
|
context: TContext;
|
|
437
437
|
}) => Promise<any>);
|
|
438
438
|
context: TContext;
|
|
439
|
-
hooks?: SubagentHooks<
|
|
439
|
+
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
440
440
|
}): SubagentConfig<TResult>;
|
|
441
441
|
declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType>(config: Omit<SubagentConfig<TResult>, "hooks" | "workflow"> & {
|
|
442
442
|
workflow: string | ((input: {
|
|
443
443
|
prompt: string;
|
|
444
444
|
}) => Promise<any>);
|
|
445
|
-
hooks?: SubagentHooks<
|
|
445
|
+
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
446
446
|
}): SubagentConfig<TResult>;
|
|
447
447
|
/**
|
|
448
448
|
* Utility to check if there were no tool calls besides a specific one
|
|
@@ -484,7 +484,7 @@ interface AgentFile {
|
|
|
484
484
|
*/
|
|
485
485
|
interface AgentResponse<M = StoredMessage> {
|
|
486
486
|
message: M;
|
|
487
|
-
|
|
487
|
+
rawToolCalls: RawToolCall[];
|
|
488
488
|
usage?: {
|
|
489
489
|
input_tokens?: number;
|
|
490
490
|
output_tokens?: number;
|
|
@@ -496,15 +496,13 @@ interface AgentResponse<M = StoredMessage> {
|
|
|
496
496
|
* Consumers provide these — typically by wrapping Temporal activities.
|
|
497
497
|
* Use `proxyDefaultThreadOps()` for the default StoredMessage implementation.
|
|
498
498
|
*/
|
|
499
|
-
interface ThreadOps
|
|
499
|
+
interface ThreadOps {
|
|
500
500
|
/** Initialize an empty thread */
|
|
501
501
|
initializeThread(threadId: string): Promise<void>;
|
|
502
502
|
/** Append a human message to the thread */
|
|
503
503
|
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
504
504
|
/** Append a tool result to the thread */
|
|
505
505
|
appendToolResult(config: ToolResultConfig): Promise<void>;
|
|
506
|
-
/** Extract raw tool calls from a message */
|
|
507
|
-
parseToolCalls(message: M): Promise<RawToolCall[]>;
|
|
508
506
|
}
|
|
509
507
|
/**
|
|
510
508
|
* Configuration for a Zeitlich agent session
|
|
@@ -517,7 +515,7 @@ interface ZeitlichAgentConfig<T extends ToolMap, M = StoredMessage> {
|
|
|
517
515
|
/** Workflow-specific runAgent activity (with tools pre-bound) */
|
|
518
516
|
runAgent: RunAgentActivity<M>;
|
|
519
517
|
/** Thread operations (initialize, append messages, parse tool calls) */
|
|
520
|
-
threadOps: ThreadOps
|
|
518
|
+
threadOps: ThreadOps;
|
|
521
519
|
/** Tool router for processing tool calls (optional if agent has no tools) */
|
|
522
520
|
tools?: T;
|
|
523
521
|
/** Subagent configurations */
|
|
@@ -925,17 +923,7 @@ declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentN
|
|
|
925
923
|
* });
|
|
926
924
|
* ```
|
|
927
925
|
*/
|
|
928
|
-
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ThreadOps
|
|
929
|
-
|
|
930
|
-
/**
|
|
931
|
-
* Result from a task handler execution
|
|
932
|
-
*/
|
|
933
|
-
interface TaskHandlerResult<TResult = unknown> {
|
|
934
|
-
/** The validated result from the child workflow */
|
|
935
|
-
result: TResult;
|
|
936
|
-
/** The child workflow ID (for reference/debugging) */
|
|
937
|
-
childWorkflowId: string;
|
|
938
|
-
}
|
|
926
|
+
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ThreadOps;
|
|
939
927
|
|
|
940
928
|
/**
|
|
941
929
|
* Shared Zeitlich activities - thread management and message handling
|
|
@@ -959,11 +947,6 @@ interface ZeitlichSharedActivities {
|
|
|
959
947
|
* Append a human message to a thread.
|
|
960
948
|
*/
|
|
961
949
|
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
962
|
-
/**
|
|
963
|
-
* Extract raw tool calls from a stored message.
|
|
964
|
-
* Returns unvalidated tool calls - use toolRegistry.parseToolCall() to validate.
|
|
965
|
-
*/
|
|
966
|
-
parseToolCalls(storedMessage: StoredMessage): Promise<RawToolCall[]>;
|
|
967
950
|
}
|
|
968
951
|
/**
|
|
969
952
|
* Creates shared Temporal activities for thread management
|
|
@@ -1143,4 +1126,4 @@ declare const bashTool: {
|
|
|
1143
1126
|
};
|
|
1144
1127
|
type BashArgs = z.infer<typeof bashTool.schema>;
|
|
1145
1128
|
|
|
1146
|
-
export { type
|
|
1129
|
+
export { type ToolArgs as $, type AgentResponse as A, type BashArgs as B, type RunAgentConfig as C, type SessionEndHookContext as D, type SessionExitReason as E, type FileEditArgs as F, type GlobArgs as G, type SessionLifecycleHooks as H, type InferToolResults as I, type JsonPrimitive as J, type SessionStartHook as K, type SessionStartHookContext as L, type SubagentArgs as M, type SubagentConfig as N, type SubagentHooks as O, type ParsedToolCall as P, type SubagentInput as Q, type RawToolCall as R, type SessionEndHook as S, type TaskCreateArgs as T, type TaskGetArgs as U, type TaskListArgs as V, type TaskStatus as W, type TaskUpdateArgs as X, type ThreadManager as Y, type ThreadManagerConfig as Z, type ThreadOps as _, type ActivityToolHandler as a, type ToolCallResult as a0, type ToolCallResultUnion as a1, type ToolDefinition as a2, type ToolHandler as a3, type ToolHandlerContext as a4, type ToolHandlerResponse as a5, type ToolHooks as a6, type ToolMap as a7, type ToolMessageContent as a8, type ToolNames as a9, grepTool as aA, hasNoOtherToolCalls as aB, isTerminalStatus as aC, proxyDefaultThreadOps as aD, readTool as aE, taskCreateTool as aF, taskGetTool as aG, taskListTool as aH, taskUpdateTool as aI, withAutoAppend as aJ, writeTool as aK, type ToolResult as aa, type ToolResultConfig as ab, type ToolRouter as ac, type ToolWithHandler as ad, type WorkflowTask as ae, type ZeitlichAgentConfig as af, type ZeitlichSession as ag, type ZeitlichSharedActivities as ah, askUserQuestionTool as ai, bashTool as aj, createAgentStateManager as ak, createBashToolDescription as al, createSession as am, createSharedActivities as an, createSubagentTool as ao, createTaskCreateHandler as ap, createTaskGetHandler as aq, createTaskListHandler as ar, createTaskUpdateHandler as as, createThreadManager as at, createToolRouter as au, defineSubagent as av, defineTool as aw, editTool as ax, getStateQuery as ay, globTool as az, type AskUserQuestionArgs as b, AGENT_HANDLER_NAMES as c, type AgentFile as d, type AgentState as e, type AgentStateManager as f, type AgentStatus as g, type AppendToolResultFn as h, type BaseAgentState as i, type BaseThreadManager as j, type FileReadArgs as k, type FileWriteArgs as l, type GrepArgs as m, type JsonSerializable as n, type JsonValue as o, type ParsedToolCallUnion as p, type PostToolUseFailureHook as q, type PostToolUseFailureHookContext as r, type PostToolUseFailureHookResult as s, type PostToolUseHook as t, type PostToolUseHookContext as u, type PreToolUseHook as v, type PreToolUseHookContext as w, type PreToolUseHookResult as x, type ProcessToolCallsContext as y, type RunAgentActivity as z };
|
|
@@ -58,13 +58,13 @@ declare function createThreadManager(config: ThreadManagerConfig): ThreadManager
|
|
|
58
58
|
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* Creates a
|
|
61
|
+
* Creates a Subagent tool configured with the available subagents.
|
|
62
62
|
*
|
|
63
63
|
* @param subagents - Array of subagent configurations (must have at least one)
|
|
64
64
|
* @returns A tool definition with dynamic schema based on available subagents
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
67
|
-
* const
|
|
67
|
+
* const subagentTool = createSubagentTool([
|
|
68
68
|
* {
|
|
69
69
|
* name: "researcher",
|
|
70
70
|
* description: "Researches topics and gathers information",
|
|
@@ -73,7 +73,7 @@ declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThr
|
|
|
73
73
|
* },
|
|
74
74
|
* ]);
|
|
75
75
|
*/
|
|
76
|
-
declare function
|
|
76
|
+
declare function createSubagentTool<T extends SubagentConfig[]>(subagents: T): {
|
|
77
77
|
name: string;
|
|
78
78
|
description: string;
|
|
79
79
|
schema: z.ZodObject<{
|
|
@@ -83,9 +83,9 @@ declare function createTaskTool<T extends SubagentConfig[]>(subagents: T): {
|
|
|
83
83
|
}>;
|
|
84
84
|
};
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
86
|
+
* Subagent tool args type (when subagent names are not known at compile time)
|
|
87
87
|
*/
|
|
88
|
-
type
|
|
88
|
+
type SubagentArgs = {
|
|
89
89
|
subagent: string;
|
|
90
90
|
description: string;
|
|
91
91
|
prompt: string;
|
|
@@ -436,13 +436,13 @@ declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType, TCont
|
|
|
436
436
|
context: TContext;
|
|
437
437
|
}) => Promise<any>);
|
|
438
438
|
context: TContext;
|
|
439
|
-
hooks?: SubagentHooks<
|
|
439
|
+
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
440
440
|
}): SubagentConfig<TResult>;
|
|
441
441
|
declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType>(config: Omit<SubagentConfig<TResult>, "hooks" | "workflow"> & {
|
|
442
442
|
workflow: string | ((input: {
|
|
443
443
|
prompt: string;
|
|
444
444
|
}) => Promise<any>);
|
|
445
|
-
hooks?: SubagentHooks<
|
|
445
|
+
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
446
446
|
}): SubagentConfig<TResult>;
|
|
447
447
|
/**
|
|
448
448
|
* Utility to check if there were no tool calls besides a specific one
|
|
@@ -484,7 +484,7 @@ interface AgentFile {
|
|
|
484
484
|
*/
|
|
485
485
|
interface AgentResponse<M = StoredMessage> {
|
|
486
486
|
message: M;
|
|
487
|
-
|
|
487
|
+
rawToolCalls: RawToolCall[];
|
|
488
488
|
usage?: {
|
|
489
489
|
input_tokens?: number;
|
|
490
490
|
output_tokens?: number;
|
|
@@ -496,15 +496,13 @@ interface AgentResponse<M = StoredMessage> {
|
|
|
496
496
|
* Consumers provide these — typically by wrapping Temporal activities.
|
|
497
497
|
* Use `proxyDefaultThreadOps()` for the default StoredMessage implementation.
|
|
498
498
|
*/
|
|
499
|
-
interface ThreadOps
|
|
499
|
+
interface ThreadOps {
|
|
500
500
|
/** Initialize an empty thread */
|
|
501
501
|
initializeThread(threadId: string): Promise<void>;
|
|
502
502
|
/** Append a human message to the thread */
|
|
503
503
|
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
504
504
|
/** Append a tool result to the thread */
|
|
505
505
|
appendToolResult(config: ToolResultConfig): Promise<void>;
|
|
506
|
-
/** Extract raw tool calls from a message */
|
|
507
|
-
parseToolCalls(message: M): Promise<RawToolCall[]>;
|
|
508
506
|
}
|
|
509
507
|
/**
|
|
510
508
|
* Configuration for a Zeitlich agent session
|
|
@@ -517,7 +515,7 @@ interface ZeitlichAgentConfig<T extends ToolMap, M = StoredMessage> {
|
|
|
517
515
|
/** Workflow-specific runAgent activity (with tools pre-bound) */
|
|
518
516
|
runAgent: RunAgentActivity<M>;
|
|
519
517
|
/** Thread operations (initialize, append messages, parse tool calls) */
|
|
520
|
-
threadOps: ThreadOps
|
|
518
|
+
threadOps: ThreadOps;
|
|
521
519
|
/** Tool router for processing tool calls (optional if agent has no tools) */
|
|
522
520
|
tools?: T;
|
|
523
521
|
/** Subagent configurations */
|
|
@@ -925,17 +923,7 @@ declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentN
|
|
|
925
923
|
* });
|
|
926
924
|
* ```
|
|
927
925
|
*/
|
|
928
|
-
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ThreadOps
|
|
929
|
-
|
|
930
|
-
/**
|
|
931
|
-
* Result from a task handler execution
|
|
932
|
-
*/
|
|
933
|
-
interface TaskHandlerResult<TResult = unknown> {
|
|
934
|
-
/** The validated result from the child workflow */
|
|
935
|
-
result: TResult;
|
|
936
|
-
/** The child workflow ID (for reference/debugging) */
|
|
937
|
-
childWorkflowId: string;
|
|
938
|
-
}
|
|
926
|
+
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ThreadOps;
|
|
939
927
|
|
|
940
928
|
/**
|
|
941
929
|
* Shared Zeitlich activities - thread management and message handling
|
|
@@ -959,11 +947,6 @@ interface ZeitlichSharedActivities {
|
|
|
959
947
|
* Append a human message to a thread.
|
|
960
948
|
*/
|
|
961
949
|
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
962
|
-
/**
|
|
963
|
-
* Extract raw tool calls from a stored message.
|
|
964
|
-
* Returns unvalidated tool calls - use toolRegistry.parseToolCall() to validate.
|
|
965
|
-
*/
|
|
966
|
-
parseToolCalls(storedMessage: StoredMessage): Promise<RawToolCall[]>;
|
|
967
950
|
}
|
|
968
951
|
/**
|
|
969
952
|
* Creates shared Temporal activities for thread management
|
|
@@ -1143,4 +1126,4 @@ declare const bashTool: {
|
|
|
1143
1126
|
};
|
|
1144
1127
|
type BashArgs = z.infer<typeof bashTool.schema>;
|
|
1145
1128
|
|
|
1146
|
-
export { type
|
|
1129
|
+
export { type ToolArgs as $, type AgentResponse as A, type BashArgs as B, type RunAgentConfig as C, type SessionEndHookContext as D, type SessionExitReason as E, type FileEditArgs as F, type GlobArgs as G, type SessionLifecycleHooks as H, type InferToolResults as I, type JsonPrimitive as J, type SessionStartHook as K, type SessionStartHookContext as L, type SubagentArgs as M, type SubagentConfig as N, type SubagentHooks as O, type ParsedToolCall as P, type SubagentInput as Q, type RawToolCall as R, type SessionEndHook as S, type TaskCreateArgs as T, type TaskGetArgs as U, type TaskListArgs as V, type TaskStatus as W, type TaskUpdateArgs as X, type ThreadManager as Y, type ThreadManagerConfig as Z, type ThreadOps as _, type ActivityToolHandler as a, type ToolCallResult as a0, type ToolCallResultUnion as a1, type ToolDefinition as a2, type ToolHandler as a3, type ToolHandlerContext as a4, type ToolHandlerResponse as a5, type ToolHooks as a6, type ToolMap as a7, type ToolMessageContent as a8, type ToolNames as a9, grepTool as aA, hasNoOtherToolCalls as aB, isTerminalStatus as aC, proxyDefaultThreadOps as aD, readTool as aE, taskCreateTool as aF, taskGetTool as aG, taskListTool as aH, taskUpdateTool as aI, withAutoAppend as aJ, writeTool as aK, type ToolResult as aa, type ToolResultConfig as ab, type ToolRouter as ac, type ToolWithHandler as ad, type WorkflowTask as ae, type ZeitlichAgentConfig as af, type ZeitlichSession as ag, type ZeitlichSharedActivities as ah, askUserQuestionTool as ai, bashTool as aj, createAgentStateManager as ak, createBashToolDescription as al, createSession as am, createSharedActivities as an, createSubagentTool as ao, createTaskCreateHandler as ap, createTaskGetHandler as aq, createTaskListHandler as ar, createTaskUpdateHandler as as, createThreadManager as at, createToolRouter as au, defineSubagent as av, defineTool as aw, editTool as ax, getStateQuery as ay, globTool as az, type AskUserQuestionArgs as b, AGENT_HANDLER_NAMES as c, type AgentFile as d, type AgentState as e, type AgentStateManager as f, type AgentStatus as g, type AppendToolResultFn as h, type BaseAgentState as i, type BaseThreadManager as j, type FileReadArgs as k, type FileWriteArgs as l, type GrepArgs as m, type JsonSerializable as n, type JsonValue as o, type ParsedToolCallUnion as p, type PostToolUseFailureHook as q, type PostToolUseFailureHookContext as r, type PostToolUseFailureHookResult as s, type PostToolUseHook as t, type PostToolUseHookContext as u, type PreToolUseHook as v, type PreToolUseHookContext as w, type PreToolUseHookResult as x, type ProcessToolCallsContext as y, type RunAgentActivity as z };
|
package/dist/workflow.cjs
CHANGED
|
@@ -8,38 +8,38 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
8
8
|
var z3__default = /*#__PURE__*/_interopDefault(z3);
|
|
9
9
|
|
|
10
10
|
// src/lib/session.ts
|
|
11
|
-
var
|
|
12
|
-
function
|
|
11
|
+
var SUBAGENT_TOOL = "Subagent";
|
|
12
|
+
function buildSubagentDescription(subagents) {
|
|
13
13
|
const subagentList = subagents.map((s) => `- **${s.name}**: ${s.description}`).join("\n");
|
|
14
|
-
return `Launch a new agent to handle complex
|
|
14
|
+
return `Launch a new agent to handle complex tasks autonomously.
|
|
15
15
|
|
|
16
|
-
The ${
|
|
16
|
+
The ${SUBAGENT_TOOL} tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
|
|
17
17
|
|
|
18
18
|
Available agent types:
|
|
19
19
|
|
|
20
20
|
${subagentList}
|
|
21
21
|
|
|
22
|
-
When using the ${
|
|
22
|
+
When using the ${SUBAGENT_TOOL} tool, you must specify a subagent parameter to select which agent type to use.
|
|
23
23
|
|
|
24
24
|
Usage notes:
|
|
25
25
|
|
|
26
26
|
- Always include a short description (3-5 words) summarizing what the agent will do
|
|
27
27
|
- Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
|
|
28
|
-
- When the agent is done, it will return a single message back to you.
|
|
28
|
+
- When the agent is done, it will return a single message back to you.
|
|
29
29
|
- Each invocation starts fresh - provide a detailed task description with all necessary context.
|
|
30
30
|
- Provide clear, detailed prompts so the agent can work autonomously and return exactly the information you need.
|
|
31
31
|
- The agent's outputs should generally be trusted
|
|
32
32
|
- Clearly tell the agent what type of work you expect since it is not aware of the user's intent
|
|
33
33
|
- If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.`;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function createSubagentTool(subagents) {
|
|
36
36
|
if (subagents.length === 0) {
|
|
37
37
|
throw new Error("createTaskTool requires at least one subagent");
|
|
38
38
|
}
|
|
39
39
|
const names = subagents.map((s) => s.name);
|
|
40
40
|
return {
|
|
41
|
-
name:
|
|
42
|
-
description:
|
|
41
|
+
name: SUBAGENT_TOOL,
|
|
42
|
+
description: buildSubagentDescription(subagents),
|
|
43
43
|
schema: z3__default.default.object({
|
|
44
44
|
subagent: z3__default.default.enum(names).describe("The type of subagent to launch"),
|
|
45
45
|
description: z3__default.default.string().describe("A short (3-5 word) description of the task"),
|
|
@@ -47,7 +47,7 @@ function createTaskTool(subagents) {
|
|
|
47
47
|
})
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function createSubagentHandler(subagents) {
|
|
51
51
|
const { workflowId: parentWorkflowId, taskQueue: parentTaskQueue } = workflow.workflowInfo();
|
|
52
52
|
return async (args) => {
|
|
53
53
|
const config = subagents.find((s) => s.name === args.subagent);
|
|
@@ -66,15 +66,11 @@ function createTaskHandler(subagents) {
|
|
|
66
66
|
args: [input],
|
|
67
67
|
taskQueue: config.taskQueue ?? parentTaskQueue
|
|
68
68
|
};
|
|
69
|
-
const
|
|
70
|
-
const validated = config.resultSchema ? config.resultSchema.parse(
|
|
71
|
-
const toolResponse = typeof validated === "string" ? validated : JSON.stringify(validated, null, 2);
|
|
69
|
+
const { toolResponse, data } = typeof config.workflow === "string" ? await workflow.executeChild(config.workflow, childOpts) : await workflow.executeChild(config.workflow, childOpts);
|
|
70
|
+
const validated = config.resultSchema ? config.resultSchema.parse(data) : null;
|
|
72
71
|
return {
|
|
73
72
|
toolResponse,
|
|
74
|
-
data:
|
|
75
|
-
result: validated,
|
|
76
|
-
childWorkflowId
|
|
77
|
-
}
|
|
73
|
+
data: validated
|
|
78
74
|
};
|
|
79
75
|
};
|
|
80
76
|
}
|
|
@@ -93,9 +89,9 @@ function createToolRouter(options) {
|
|
|
93
89
|
if (s.hooks) subagentHooksMap.set(s.name, s.hooks);
|
|
94
90
|
}
|
|
95
91
|
const resolveSubagentName = (args) => args.subagent;
|
|
96
|
-
toolMap.set("
|
|
97
|
-
...
|
|
98
|
-
handler:
|
|
92
|
+
toolMap.set("Subagent", {
|
|
93
|
+
...createSubagentTool(options.subagents),
|
|
94
|
+
handler: createSubagentHandler(options.subagents),
|
|
99
95
|
...subagentHooksMap.size > 0 && {
|
|
100
96
|
hooks: {
|
|
101
97
|
onPreToolUse: async (ctx) => {
|
|
@@ -431,22 +427,16 @@ var createSession = async ({
|
|
|
431
427
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
432
428
|
stateManager.incrementTurns();
|
|
433
429
|
const currentTurn = stateManager.getTurns();
|
|
434
|
-
const { message,
|
|
430
|
+
const { message, rawToolCalls } = await runAgent({
|
|
435
431
|
threadId,
|
|
436
432
|
agentName,
|
|
437
433
|
metadata
|
|
438
434
|
});
|
|
439
|
-
if (
|
|
440
|
-
stateManager.complete();
|
|
441
|
-
exitReason = "completed";
|
|
442
|
-
return message;
|
|
443
|
-
}
|
|
444
|
-
if (!toolRouter.hasTools()) {
|
|
435
|
+
if (!toolRouter.hasTools() || rawToolCalls.length === 0) {
|
|
445
436
|
stateManager.complete();
|
|
446
437
|
exitReason = "completed";
|
|
447
438
|
return message;
|
|
448
439
|
}
|
|
449
|
-
const rawToolCalls = await threadOps.parseToolCalls(message);
|
|
450
440
|
const parsedToolCalls = [];
|
|
451
441
|
for (const tc of rawToolCalls) {
|
|
452
442
|
try {
|
|
@@ -499,8 +489,7 @@ function proxyDefaultThreadOps(options) {
|
|
|
499
489
|
return {
|
|
500
490
|
initializeThread: activities.initializeThread,
|
|
501
491
|
appendHumanMessage: activities.appendHumanMessage,
|
|
502
|
-
appendToolResult: activities.appendToolResult
|
|
503
|
-
parseToolCalls: activities.parseToolCalls
|
|
492
|
+
appendToolResult: activities.appendToolResult
|
|
504
493
|
};
|
|
505
494
|
}
|
|
506
495
|
|
|
@@ -973,10 +962,10 @@ exports.bashTool = bashTool;
|
|
|
973
962
|
exports.createAgentStateManager = createAgentStateManager;
|
|
974
963
|
exports.createBashToolDescription = createBashToolDescription;
|
|
975
964
|
exports.createSession = createSession;
|
|
965
|
+
exports.createSubagentTool = createSubagentTool;
|
|
976
966
|
exports.createTaskCreateHandler = createTaskCreateHandler;
|
|
977
967
|
exports.createTaskGetHandler = createTaskGetHandler;
|
|
978
968
|
exports.createTaskListHandler = createTaskListHandler;
|
|
979
|
-
exports.createTaskTool = createTaskTool;
|
|
980
969
|
exports.createTaskUpdateHandler = createTaskUpdateHandler;
|
|
981
970
|
exports.createToolRouter = createToolRouter;
|
|
982
971
|
exports.defineSubagent = defineSubagent;
|