zeitlich 0.2.3 → 0.2.5
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 +70 -40
- package/dist/index.cjs +83 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +84 -72
- package/dist/index.js.map +1 -1
- package/dist/{workflow-D-2vp4Pq.d.cts → workflow-Dg5JMeOC.d.cts} +27 -30
- package/dist/{workflow-D-2vp4Pq.d.ts → workflow-Dg5JMeOC.d.ts} +27 -30
- package/dist/workflow.cjs +67 -61
- 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 +67 -61
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/activities.ts +8 -16
- package/src/index.ts +4 -4
- package/src/lib/model-invoker.ts +12 -5
- package/src/lib/session.ts +20 -19
- package/src/lib/thread-manager.ts +2 -3
- package/src/lib/tool-router.ts +45 -36
- package/src/lib/types.ts +16 -6
- package/src/tools/subagent/handler.ts +71 -0
- package/src/tools/{task → subagent}/tool.ts +16 -16
- package/src/workflow.ts +4 -5
- package/src/tools/task/handler.ts +0 -85
|
@@ -44,6 +44,8 @@ interface ThreadManager extends BaseThreadManager<StoredMessage> {
|
|
|
44
44
|
createToolMessage(content: ToolMessageContent, toolCallId: string): StoredMessage;
|
|
45
45
|
/** Create and append a HumanMessage */
|
|
46
46
|
appendHumanMessage(content: string | MessageContent): Promise<void>;
|
|
47
|
+
/** Create and append a SystemMessage */
|
|
48
|
+
appendSystemMessage(content: string): Promise<void>;
|
|
47
49
|
/** Create and append a ToolMessage */
|
|
48
50
|
appendToolMessage(content: ToolMessageContent, toolCallId: string): Promise<void>;
|
|
49
51
|
/** Create and append an AIMessage */
|
|
@@ -58,22 +60,22 @@ declare function createThreadManager(config: ThreadManagerConfig): ThreadManager
|
|
|
58
60
|
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
|
-
* Creates a
|
|
63
|
+
* Creates a Subagent tool configured with the available subagents.
|
|
62
64
|
*
|
|
63
65
|
* @param subagents - Array of subagent configurations (must have at least one)
|
|
64
66
|
* @returns A tool definition with dynamic schema based on available subagents
|
|
65
67
|
*
|
|
66
68
|
* @example
|
|
67
|
-
* const
|
|
69
|
+
* const subagentTool = createSubagentTool([
|
|
68
70
|
* {
|
|
69
|
-
*
|
|
71
|
+
* agentName: "researcher",
|
|
70
72
|
* description: "Researches topics and gathers information",
|
|
71
73
|
* workflow: "researcherWorkflow",
|
|
72
74
|
* resultSchema: z.object({ findings: z.string() }),
|
|
73
75
|
* },
|
|
74
76
|
* ]);
|
|
75
77
|
*/
|
|
76
|
-
declare function
|
|
78
|
+
declare function createSubagentTool<T extends SubagentConfig[]>(subagents: T): {
|
|
77
79
|
name: string;
|
|
78
80
|
description: string;
|
|
79
81
|
schema: z.ZodObject<{
|
|
@@ -83,9 +85,9 @@ declare function createTaskTool<T extends SubagentConfig[]>(subagents: T): {
|
|
|
83
85
|
}>;
|
|
84
86
|
};
|
|
85
87
|
/**
|
|
86
|
-
*
|
|
88
|
+
* Subagent tool args type (when subagent names are not known at compile time)
|
|
87
89
|
*/
|
|
88
|
-
type
|
|
90
|
+
type SubagentArgs = {
|
|
89
91
|
subagent: string;
|
|
90
92
|
description: string;
|
|
91
93
|
prompt: string;
|
|
@@ -436,13 +438,13 @@ declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType, TCont
|
|
|
436
438
|
context: TContext;
|
|
437
439
|
}) => Promise<any>);
|
|
438
440
|
context: TContext;
|
|
439
|
-
hooks?: SubagentHooks<
|
|
441
|
+
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
440
442
|
}): SubagentConfig<TResult>;
|
|
441
443
|
declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType>(config: Omit<SubagentConfig<TResult>, "hooks" | "workflow"> & {
|
|
442
444
|
workflow: string | ((input: {
|
|
443
445
|
prompt: string;
|
|
444
446
|
}) => Promise<any>);
|
|
445
|
-
hooks?: SubagentHooks<
|
|
447
|
+
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
446
448
|
}): SubagentConfig<TResult>;
|
|
447
449
|
/**
|
|
448
450
|
* Utility to check if there were no tool calls besides a specific one
|
|
@@ -484,7 +486,7 @@ interface AgentFile {
|
|
|
484
486
|
*/
|
|
485
487
|
interface AgentResponse<M = StoredMessage> {
|
|
486
488
|
message: M;
|
|
487
|
-
|
|
489
|
+
rawToolCalls: RawToolCall[];
|
|
488
490
|
usage?: {
|
|
489
491
|
input_tokens?: number;
|
|
490
492
|
output_tokens?: number;
|
|
@@ -496,15 +498,15 @@ interface AgentResponse<M = StoredMessage> {
|
|
|
496
498
|
* Consumers provide these — typically by wrapping Temporal activities.
|
|
497
499
|
* Use `proxyDefaultThreadOps()` for the default StoredMessage implementation.
|
|
498
500
|
*/
|
|
499
|
-
interface ThreadOps
|
|
501
|
+
interface ThreadOps {
|
|
500
502
|
/** Initialize an empty thread */
|
|
501
503
|
initializeThread(threadId: string): Promise<void>;
|
|
502
504
|
/** Append a human message to the thread */
|
|
503
505
|
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
504
506
|
/** Append a tool result to the thread */
|
|
505
507
|
appendToolResult(config: ToolResultConfig): Promise<void>;
|
|
506
|
-
/**
|
|
507
|
-
|
|
508
|
+
/** Append a system message to the thread */
|
|
509
|
+
appendSystemMessage(threadId: string, content: string): Promise<void>;
|
|
508
510
|
}
|
|
509
511
|
/**
|
|
510
512
|
* Configuration for a Zeitlich agent session
|
|
@@ -512,12 +514,16 @@ interface ThreadOps<M = StoredMessage> {
|
|
|
512
514
|
interface ZeitlichAgentConfig<T extends ToolMap, M = StoredMessage> {
|
|
513
515
|
threadId: string;
|
|
514
516
|
agentName: string;
|
|
517
|
+
/** Description, used for sub agents */
|
|
518
|
+
description?: string;
|
|
519
|
+
systemPrompt?: string;
|
|
515
520
|
metadata?: Record<string, unknown>;
|
|
521
|
+
appendSystemPrompt?: boolean;
|
|
516
522
|
maxTurns?: number;
|
|
517
523
|
/** Workflow-specific runAgent activity (with tools pre-bound) */
|
|
518
524
|
runAgent: RunAgentActivity<M>;
|
|
519
525
|
/** Thread operations (initialize, append messages, parse tool calls) */
|
|
520
|
-
threadOps
|
|
526
|
+
threadOps?: ThreadOps;
|
|
521
527
|
/** Tool router for processing tool calls (optional if agent has no tools) */
|
|
522
528
|
tools?: T;
|
|
523
529
|
/** Subagent configurations */
|
|
@@ -574,9 +580,11 @@ interface ToolResultConfig {
|
|
|
574
580
|
*/
|
|
575
581
|
interface SubagentConfig<TResult extends z$1.ZodType = z$1.ZodType> {
|
|
576
582
|
/** Identifier used in Task tool's subagent parameter */
|
|
577
|
-
|
|
583
|
+
agentName: string;
|
|
578
584
|
/** Description shown to the parent agent explaining what this subagent does */
|
|
579
585
|
description: string;
|
|
586
|
+
/** Whether this subagent is available (default: true). Disabled subagents are excluded from the Subagent tool. */
|
|
587
|
+
enabled?: boolean;
|
|
580
588
|
/** Temporal workflow function or type name (used with executeChild) */
|
|
581
589
|
workflow: string | Workflow;
|
|
582
590
|
/** Optional task queue - defaults to parent's queue if not specified */
|
|
@@ -912,7 +920,7 @@ interface SessionLifecycleHooks {
|
|
|
912
920
|
/** Called when session ends */
|
|
913
921
|
onSessionEnd?: SessionEndHook;
|
|
914
922
|
}
|
|
915
|
-
declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentName, maxTurns, metadata, runAgent, threadOps, buildContextMessage, subagents, tools, processToolsInParallel, hooks, }: ZeitlichAgentConfig<T, M>) => Promise<ZeitlichSession<M>>;
|
|
923
|
+
declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentName, maxTurns, metadata, runAgent, threadOps, buildContextMessage, subagents, tools, processToolsInParallel, hooks, appendSystemPrompt, systemPrompt, }: ZeitlichAgentConfig<T, M>) => Promise<ZeitlichSession<M>>;
|
|
916
924
|
/**
|
|
917
925
|
* Proxy the default ZeitlichSharedActivities as ThreadOps<StoredMessage>.
|
|
918
926
|
* Call this in workflow code for the standard LangChain/StoredMessage setup.
|
|
@@ -925,17 +933,7 @@ declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentN
|
|
|
925
933
|
* });
|
|
926
934
|
* ```
|
|
927
935
|
*/
|
|
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
|
-
}
|
|
936
|
+
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ThreadOps;
|
|
939
937
|
|
|
940
938
|
/**
|
|
941
939
|
* Shared Zeitlich activities - thread management and message handling
|
|
@@ -960,10 +958,9 @@ interface ZeitlichSharedActivities {
|
|
|
960
958
|
*/
|
|
961
959
|
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
962
960
|
/**
|
|
963
|
-
*
|
|
964
|
-
* Returns unvalidated tool calls - use toolRegistry.parseToolCall() to validate.
|
|
961
|
+
* Append a system message to a thread.
|
|
965
962
|
*/
|
|
966
|
-
|
|
963
|
+
appendSystemMessage(threadId: string, content: string): Promise<void>;
|
|
967
964
|
}
|
|
968
965
|
/**
|
|
969
966
|
* Creates shared Temporal activities for thread management
|
|
@@ -1143,4 +1140,4 @@ declare const bashTool: {
|
|
|
1143
1140
|
};
|
|
1144
1141
|
type BashArgs = z.infer<typeof bashTool.schema>;
|
|
1145
1142
|
|
|
1146
|
-
export { type
|
|
1143
|
+
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 };
|
|
@@ -44,6 +44,8 @@ interface ThreadManager extends BaseThreadManager<StoredMessage> {
|
|
|
44
44
|
createToolMessage(content: ToolMessageContent, toolCallId: string): StoredMessage;
|
|
45
45
|
/** Create and append a HumanMessage */
|
|
46
46
|
appendHumanMessage(content: string | MessageContent): Promise<void>;
|
|
47
|
+
/** Create and append a SystemMessage */
|
|
48
|
+
appendSystemMessage(content: string): Promise<void>;
|
|
47
49
|
/** Create and append a ToolMessage */
|
|
48
50
|
appendToolMessage(content: ToolMessageContent, toolCallId: string): Promise<void>;
|
|
49
51
|
/** Create and append an AIMessage */
|
|
@@ -58,22 +60,22 @@ declare function createThreadManager(config: ThreadManagerConfig): ThreadManager
|
|
|
58
60
|
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
|
-
* Creates a
|
|
63
|
+
* Creates a Subagent tool configured with the available subagents.
|
|
62
64
|
*
|
|
63
65
|
* @param subagents - Array of subagent configurations (must have at least one)
|
|
64
66
|
* @returns A tool definition with dynamic schema based on available subagents
|
|
65
67
|
*
|
|
66
68
|
* @example
|
|
67
|
-
* const
|
|
69
|
+
* const subagentTool = createSubagentTool([
|
|
68
70
|
* {
|
|
69
|
-
*
|
|
71
|
+
* agentName: "researcher",
|
|
70
72
|
* description: "Researches topics and gathers information",
|
|
71
73
|
* workflow: "researcherWorkflow",
|
|
72
74
|
* resultSchema: z.object({ findings: z.string() }),
|
|
73
75
|
* },
|
|
74
76
|
* ]);
|
|
75
77
|
*/
|
|
76
|
-
declare function
|
|
78
|
+
declare function createSubagentTool<T extends SubagentConfig[]>(subagents: T): {
|
|
77
79
|
name: string;
|
|
78
80
|
description: string;
|
|
79
81
|
schema: z.ZodObject<{
|
|
@@ -83,9 +85,9 @@ declare function createTaskTool<T extends SubagentConfig[]>(subagents: T): {
|
|
|
83
85
|
}>;
|
|
84
86
|
};
|
|
85
87
|
/**
|
|
86
|
-
*
|
|
88
|
+
* Subagent tool args type (when subagent names are not known at compile time)
|
|
87
89
|
*/
|
|
88
|
-
type
|
|
90
|
+
type SubagentArgs = {
|
|
89
91
|
subagent: string;
|
|
90
92
|
description: string;
|
|
91
93
|
prompt: string;
|
|
@@ -436,13 +438,13 @@ declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType, TCont
|
|
|
436
438
|
context: TContext;
|
|
437
439
|
}) => Promise<any>);
|
|
438
440
|
context: TContext;
|
|
439
|
-
hooks?: SubagentHooks<
|
|
441
|
+
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
440
442
|
}): SubagentConfig<TResult>;
|
|
441
443
|
declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType>(config: Omit<SubagentConfig<TResult>, "hooks" | "workflow"> & {
|
|
442
444
|
workflow: string | ((input: {
|
|
443
445
|
prompt: string;
|
|
444
446
|
}) => Promise<any>);
|
|
445
|
-
hooks?: SubagentHooks<
|
|
447
|
+
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
446
448
|
}): SubagentConfig<TResult>;
|
|
447
449
|
/**
|
|
448
450
|
* Utility to check if there were no tool calls besides a specific one
|
|
@@ -484,7 +486,7 @@ interface AgentFile {
|
|
|
484
486
|
*/
|
|
485
487
|
interface AgentResponse<M = StoredMessage> {
|
|
486
488
|
message: M;
|
|
487
|
-
|
|
489
|
+
rawToolCalls: RawToolCall[];
|
|
488
490
|
usage?: {
|
|
489
491
|
input_tokens?: number;
|
|
490
492
|
output_tokens?: number;
|
|
@@ -496,15 +498,15 @@ interface AgentResponse<M = StoredMessage> {
|
|
|
496
498
|
* Consumers provide these — typically by wrapping Temporal activities.
|
|
497
499
|
* Use `proxyDefaultThreadOps()` for the default StoredMessage implementation.
|
|
498
500
|
*/
|
|
499
|
-
interface ThreadOps
|
|
501
|
+
interface ThreadOps {
|
|
500
502
|
/** Initialize an empty thread */
|
|
501
503
|
initializeThread(threadId: string): Promise<void>;
|
|
502
504
|
/** Append a human message to the thread */
|
|
503
505
|
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
504
506
|
/** Append a tool result to the thread */
|
|
505
507
|
appendToolResult(config: ToolResultConfig): Promise<void>;
|
|
506
|
-
/**
|
|
507
|
-
|
|
508
|
+
/** Append a system message to the thread */
|
|
509
|
+
appendSystemMessage(threadId: string, content: string): Promise<void>;
|
|
508
510
|
}
|
|
509
511
|
/**
|
|
510
512
|
* Configuration for a Zeitlich agent session
|
|
@@ -512,12 +514,16 @@ interface ThreadOps<M = StoredMessage> {
|
|
|
512
514
|
interface ZeitlichAgentConfig<T extends ToolMap, M = StoredMessage> {
|
|
513
515
|
threadId: string;
|
|
514
516
|
agentName: string;
|
|
517
|
+
/** Description, used for sub agents */
|
|
518
|
+
description?: string;
|
|
519
|
+
systemPrompt?: string;
|
|
515
520
|
metadata?: Record<string, unknown>;
|
|
521
|
+
appendSystemPrompt?: boolean;
|
|
516
522
|
maxTurns?: number;
|
|
517
523
|
/** Workflow-specific runAgent activity (with tools pre-bound) */
|
|
518
524
|
runAgent: RunAgentActivity<M>;
|
|
519
525
|
/** Thread operations (initialize, append messages, parse tool calls) */
|
|
520
|
-
threadOps
|
|
526
|
+
threadOps?: ThreadOps;
|
|
521
527
|
/** Tool router for processing tool calls (optional if agent has no tools) */
|
|
522
528
|
tools?: T;
|
|
523
529
|
/** Subagent configurations */
|
|
@@ -574,9 +580,11 @@ interface ToolResultConfig {
|
|
|
574
580
|
*/
|
|
575
581
|
interface SubagentConfig<TResult extends z$1.ZodType = z$1.ZodType> {
|
|
576
582
|
/** Identifier used in Task tool's subagent parameter */
|
|
577
|
-
|
|
583
|
+
agentName: string;
|
|
578
584
|
/** Description shown to the parent agent explaining what this subagent does */
|
|
579
585
|
description: string;
|
|
586
|
+
/** Whether this subagent is available (default: true). Disabled subagents are excluded from the Subagent tool. */
|
|
587
|
+
enabled?: boolean;
|
|
580
588
|
/** Temporal workflow function or type name (used with executeChild) */
|
|
581
589
|
workflow: string | Workflow;
|
|
582
590
|
/** Optional task queue - defaults to parent's queue if not specified */
|
|
@@ -912,7 +920,7 @@ interface SessionLifecycleHooks {
|
|
|
912
920
|
/** Called when session ends */
|
|
913
921
|
onSessionEnd?: SessionEndHook;
|
|
914
922
|
}
|
|
915
|
-
declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentName, maxTurns, metadata, runAgent, threadOps, buildContextMessage, subagents, tools, processToolsInParallel, hooks, }: ZeitlichAgentConfig<T, M>) => Promise<ZeitlichSession<M>>;
|
|
923
|
+
declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentName, maxTurns, metadata, runAgent, threadOps, buildContextMessage, subagents, tools, processToolsInParallel, hooks, appendSystemPrompt, systemPrompt, }: ZeitlichAgentConfig<T, M>) => Promise<ZeitlichSession<M>>;
|
|
916
924
|
/**
|
|
917
925
|
* Proxy the default ZeitlichSharedActivities as ThreadOps<StoredMessage>.
|
|
918
926
|
* Call this in workflow code for the standard LangChain/StoredMessage setup.
|
|
@@ -925,17 +933,7 @@ declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentN
|
|
|
925
933
|
* });
|
|
926
934
|
* ```
|
|
927
935
|
*/
|
|
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
|
-
}
|
|
936
|
+
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ThreadOps;
|
|
939
937
|
|
|
940
938
|
/**
|
|
941
939
|
* Shared Zeitlich activities - thread management and message handling
|
|
@@ -960,10 +958,9 @@ interface ZeitlichSharedActivities {
|
|
|
960
958
|
*/
|
|
961
959
|
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
962
960
|
/**
|
|
963
|
-
*
|
|
964
|
-
* Returns unvalidated tool calls - use toolRegistry.parseToolCall() to validate.
|
|
961
|
+
* Append a system message to a thread.
|
|
965
962
|
*/
|
|
966
|
-
|
|
963
|
+
appendSystemMessage(threadId: string, content: string): Promise<void>;
|
|
967
964
|
}
|
|
968
965
|
/**
|
|
969
966
|
* Creates shared Temporal activities for thread management
|
|
@@ -1143,4 +1140,4 @@ declare const bashTool: {
|
|
|
1143
1140
|
};
|
|
1144
1141
|
type BashArgs = z.infer<typeof bashTool.schema>;
|
|
1145
1142
|
|
|
1146
|
-
export { type
|
|
1143
|
+
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
|
|
13
|
-
const subagentList = subagents.map((s) => `- **${s.
|
|
14
|
-
return `Launch a new agent to handle complex
|
|
11
|
+
var SUBAGENT_TOOL = "Subagent";
|
|
12
|
+
function buildSubagentDescription(subagents) {
|
|
13
|
+
const subagentList = subagents.map((s) => `- **${s.agentName}**: ${s.description}`).join("\n");
|
|
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
|
-
const names = subagents.map((s) => s.
|
|
39
|
+
const names = subagents.map((s) => s.agentName);
|
|
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,16 +47,16 @@ function createTaskTool(subagents) {
|
|
|
47
47
|
})
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
const {
|
|
50
|
+
function createSubagentHandler(subagents) {
|
|
51
|
+
const { taskQueue: parentTaskQueue } = workflow.workflowInfo();
|
|
52
52
|
return async (args) => {
|
|
53
|
-
const config = subagents.find((s) => s.
|
|
53
|
+
const config = subagents.find((s) => s.agentName === args.subagent);
|
|
54
54
|
if (!config) {
|
|
55
55
|
throw new Error(
|
|
56
|
-
`Unknown subagent: ${args.subagent}. Available: ${subagents.map((s) => s.
|
|
56
|
+
`Unknown subagent: ${args.subagent}. Available: ${subagents.map((s) => s.agentName).join(", ")}`
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
|
-
const childWorkflowId = `${
|
|
59
|
+
const childWorkflowId = `${args.subagent}-${workflow.uuid4()}`;
|
|
60
60
|
const input = {
|
|
61
61
|
prompt: args.prompt,
|
|
62
62
|
...config.context && { context: config.context }
|
|
@@ -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
|
}
|
|
@@ -88,31 +84,36 @@ function createToolRouter(options) {
|
|
|
88
84
|
}
|
|
89
85
|
const isEnabled = (tool) => tool.enabled !== false;
|
|
90
86
|
if (options.subagents) {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
87
|
+
const enabledSubagents = options.subagents.filter(
|
|
88
|
+
(s) => s.enabled !== false
|
|
89
|
+
);
|
|
90
|
+
if (enabledSubagents.length > 0) {
|
|
91
|
+
const subagentHooksMap = /* @__PURE__ */ new Map();
|
|
92
|
+
for (const s of enabledSubagents) {
|
|
93
|
+
if (s.hooks) subagentHooksMap.set(s.agentName, s.hooks);
|
|
94
|
+
}
|
|
95
|
+
const resolveSubagentName = (args) => args.subagent;
|
|
96
|
+
toolMap.set("Subagent", {
|
|
97
|
+
...createSubagentTool(enabledSubagents),
|
|
98
|
+
handler: createSubagentHandler(enabledSubagents),
|
|
99
|
+
...subagentHooksMap.size > 0 && {
|
|
100
|
+
hooks: {
|
|
101
|
+
onPreToolUse: async (ctx) => {
|
|
102
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
103
|
+
return hooks?.onPreExecution?.(ctx) ?? {};
|
|
104
|
+
},
|
|
105
|
+
onPostToolUse: async (ctx) => {
|
|
106
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
107
|
+
await hooks?.onPostExecution?.(ctx);
|
|
108
|
+
},
|
|
109
|
+
onPostToolUseFailure: async (ctx) => {
|
|
110
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
111
|
+
return hooks?.onExecutionFailure?.(ctx) ?? {};
|
|
112
|
+
}
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
116
117
|
}
|
|
117
118
|
async function processToolCall(toolCall, turn, handlerContext) {
|
|
118
119
|
const startTime = Date.now();
|
|
@@ -393,11 +394,19 @@ var createSession = async ({
|
|
|
393
394
|
subagents,
|
|
394
395
|
tools = {},
|
|
395
396
|
processToolsInParallel = true,
|
|
396
|
-
hooks = {}
|
|
397
|
+
hooks = {},
|
|
398
|
+
appendSystemPrompt = true,
|
|
399
|
+
systemPrompt
|
|
397
400
|
}) => {
|
|
401
|
+
const {
|
|
402
|
+
appendToolResult,
|
|
403
|
+
appendHumanMessage,
|
|
404
|
+
initializeThread,
|
|
405
|
+
appendSystemMessage
|
|
406
|
+
} = threadOps ?? proxyDefaultThreadOps();
|
|
398
407
|
const toolRouter = createToolRouter({
|
|
399
408
|
tools,
|
|
400
|
-
appendToolResult
|
|
409
|
+
appendToolResult,
|
|
401
410
|
threadId,
|
|
402
411
|
hooks,
|
|
403
412
|
subagents,
|
|
@@ -424,35 +433,32 @@ var createSession = async ({
|
|
|
424
433
|
});
|
|
425
434
|
}
|
|
426
435
|
stateManager.setTools(toolRouter.getToolDefinitions());
|
|
427
|
-
await
|
|
428
|
-
|
|
436
|
+
await initializeThread(threadId);
|
|
437
|
+
if (appendSystemPrompt && systemPrompt && systemPrompt.trim() !== "") {
|
|
438
|
+
await appendSystemMessage(threadId, systemPrompt);
|
|
439
|
+
}
|
|
440
|
+
await appendHumanMessage(threadId, await buildContextMessage());
|
|
429
441
|
let exitReason = "completed";
|
|
430
442
|
try {
|
|
431
443
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
432
444
|
stateManager.incrementTurns();
|
|
433
445
|
const currentTurn = stateManager.getTurns();
|
|
434
|
-
const { message,
|
|
446
|
+
const { message, rawToolCalls } = await runAgent({
|
|
435
447
|
threadId,
|
|
436
448
|
agentName,
|
|
437
449
|
metadata
|
|
438
450
|
});
|
|
439
|
-
if (
|
|
440
|
-
stateManager.complete();
|
|
441
|
-
exitReason = "completed";
|
|
442
|
-
return message;
|
|
443
|
-
}
|
|
444
|
-
if (!toolRouter.hasTools()) {
|
|
451
|
+
if (!toolRouter.hasTools() || rawToolCalls.length === 0) {
|
|
445
452
|
stateManager.complete();
|
|
446
453
|
exitReason = "completed";
|
|
447
454
|
return message;
|
|
448
455
|
}
|
|
449
|
-
const rawToolCalls = await threadOps.parseToolCalls(message);
|
|
450
456
|
const parsedToolCalls = [];
|
|
451
457
|
for (const tc of rawToolCalls) {
|
|
452
458
|
try {
|
|
453
459
|
parsedToolCalls.push(toolRouter.parseToolCall(tc));
|
|
454
460
|
} catch (error) {
|
|
455
|
-
await
|
|
461
|
+
await appendToolResult({
|
|
456
462
|
threadId,
|
|
457
463
|
toolCallId: tc.id ?? "",
|
|
458
464
|
toolName: tc.name,
|
|
@@ -500,7 +506,7 @@ function proxyDefaultThreadOps(options) {
|
|
|
500
506
|
initializeThread: activities.initializeThread,
|
|
501
507
|
appendHumanMessage: activities.appendHumanMessage,
|
|
502
508
|
appendToolResult: activities.appendToolResult,
|
|
503
|
-
|
|
509
|
+
appendSystemMessage: activities.appendSystemMessage
|
|
504
510
|
};
|
|
505
511
|
}
|
|
506
512
|
|
|
@@ -973,10 +979,10 @@ exports.bashTool = bashTool;
|
|
|
973
979
|
exports.createAgentStateManager = createAgentStateManager;
|
|
974
980
|
exports.createBashToolDescription = createBashToolDescription;
|
|
975
981
|
exports.createSession = createSession;
|
|
982
|
+
exports.createSubagentTool = createSubagentTool;
|
|
976
983
|
exports.createTaskCreateHandler = createTaskCreateHandler;
|
|
977
984
|
exports.createTaskGetHandler = createTaskGetHandler;
|
|
978
985
|
exports.createTaskListHandler = createTaskListHandler;
|
|
979
|
-
exports.createTaskTool = createTaskTool;
|
|
980
986
|
exports.createTaskUpdateHandler = createTaskUpdateHandler;
|
|
981
987
|
exports.createToolRouter = createToolRouter;
|
|
982
988
|
exports.defineSubagent = defineSubagent;
|