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
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as AgentResponse, a as ActivityToolHandler, b as AskUserQuestionArgs, G as GlobArgs, F as FileEditArgs, B as BashArgs } from './workflow-
|
|
2
|
-
export { c as AGENT_HANDLER_NAMES, d as AgentFile, e as AgentState, f as AgentStateManager, g as AgentStatus, h as AppendToolResultFn, i as BaseAgentState, j as BaseThreadManager, k as FileReadArgs, l as FileWriteArgs, m as GrepArgs, I as InferToolResults, J as JsonPrimitive, n as JsonSerializable, o as JsonValue, P as ParsedToolCall, p as ParsedToolCallUnion, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, s as PostToolUseFailureHookResult, t as PostToolUseHook, u as PostToolUseHookContext, v as PreToolUseHook, w as PreToolUseHookContext, x as PreToolUseHookResult, y as ProcessToolCallsContext, R as RawToolCall, z as RunAgentActivity, C as RunAgentConfig, S as SessionEndHook, D as SessionEndHookContext, E as SessionExitReason, H as SessionLifecycleHooks, K as SessionStartHook, L as SessionStartHookContext, M as
|
|
1
|
+
import { A as AgentResponse, a as ActivityToolHandler, b as AskUserQuestionArgs, G as GlobArgs, F as FileEditArgs, B as BashArgs } from './workflow-PjeURKw4.cjs';
|
|
2
|
+
export { c as AGENT_HANDLER_NAMES, d as AgentFile, e as AgentState, f as AgentStateManager, g as AgentStatus, h as AppendToolResultFn, i as BaseAgentState, j as BaseThreadManager, k as FileReadArgs, l as FileWriteArgs, m as GrepArgs, I as InferToolResults, J as JsonPrimitive, n as JsonSerializable, o as JsonValue, P as ParsedToolCall, p as ParsedToolCallUnion, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, s as PostToolUseFailureHookResult, t as PostToolUseHook, u as PostToolUseHookContext, v as PreToolUseHook, w as PreToolUseHookContext, x as PreToolUseHookResult, y as ProcessToolCallsContext, R as RawToolCall, z as RunAgentActivity, C as RunAgentConfig, S as SessionEndHook, D as SessionEndHookContext, E as SessionExitReason, H as SessionLifecycleHooks, K as SessionStartHook, L as SessionStartHookContext, M as SubagentArgs, N as SubagentConfig, O as SubagentHooks, Q as SubagentInput, T as TaskCreateArgs, U as TaskGetArgs, V as TaskListArgs, W as TaskStatus, X as TaskUpdateArgs, Y as ThreadManager, Z as ThreadManagerConfig, _ as ThreadOps, $ as ToolArgs, a0 as ToolCallResult, a1 as ToolCallResultUnion, a2 as ToolDefinition, a3 as ToolHandler, a4 as ToolHandlerContext, a5 as ToolHandlerResponse, a6 as ToolHooks, a7 as ToolMap, a8 as ToolMessageContent, a9 as ToolNames, aa as ToolResult, ab as ToolResultConfig, ac as ToolRouter, ad as ToolWithHandler, ae as WorkflowTask, af as ZeitlichAgentConfig, ag as ZeitlichSession, ah as ZeitlichSharedActivities, ai as askUserQuestionTool, aj as bashTool, ak as createAgentStateManager, al as createBashToolDescription, am as createSession, an as createSharedActivities, ao as createSubagentTool, ap as createTaskCreateHandler, aq as createTaskGetHandler, ar as createTaskListHandler, as as createTaskUpdateHandler, at as createThreadManager, au as createToolRouter, av as defineSubagent, aw as defineTool, ax as editTool, ay as getStateQuery, az as globTool, aA as grepTool, aB as hasNoOtherToolCalls, aC as isTerminalStatus, aD as proxyDefaultThreadOps, aE as readTool, aF as taskCreateTool, aG as taskGetTool, aH as taskListTool, aI as taskUpdateTool, aJ as withAutoAppend, aK as writeTool } from './workflow-PjeURKw4.cjs';
|
|
3
3
|
import { SimplePlugin } from '@temporalio/plugin';
|
|
4
4
|
import Redis from 'ioredis';
|
|
5
5
|
import { WorkflowClient } from '@temporalio/client';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as AgentResponse, a as ActivityToolHandler, b as AskUserQuestionArgs, G as GlobArgs, F as FileEditArgs, B as BashArgs } from './workflow-
|
|
2
|
-
export { c as AGENT_HANDLER_NAMES, d as AgentFile, e as AgentState, f as AgentStateManager, g as AgentStatus, h as AppendToolResultFn, i as BaseAgentState, j as BaseThreadManager, k as FileReadArgs, l as FileWriteArgs, m as GrepArgs, I as InferToolResults, J as JsonPrimitive, n as JsonSerializable, o as JsonValue, P as ParsedToolCall, p as ParsedToolCallUnion, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, s as PostToolUseFailureHookResult, t as PostToolUseHook, u as PostToolUseHookContext, v as PreToolUseHook, w as PreToolUseHookContext, x as PreToolUseHookResult, y as ProcessToolCallsContext, R as RawToolCall, z as RunAgentActivity, C as RunAgentConfig, S as SessionEndHook, D as SessionEndHookContext, E as SessionExitReason, H as SessionLifecycleHooks, K as SessionStartHook, L as SessionStartHookContext, M as
|
|
1
|
+
import { A as AgentResponse, a as ActivityToolHandler, b as AskUserQuestionArgs, G as GlobArgs, F as FileEditArgs, B as BashArgs } from './workflow-PjeURKw4.js';
|
|
2
|
+
export { c as AGENT_HANDLER_NAMES, d as AgentFile, e as AgentState, f as AgentStateManager, g as AgentStatus, h as AppendToolResultFn, i as BaseAgentState, j as BaseThreadManager, k as FileReadArgs, l as FileWriteArgs, m as GrepArgs, I as InferToolResults, J as JsonPrimitive, n as JsonSerializable, o as JsonValue, P as ParsedToolCall, p as ParsedToolCallUnion, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, s as PostToolUseFailureHookResult, t as PostToolUseHook, u as PostToolUseHookContext, v as PreToolUseHook, w as PreToolUseHookContext, x as PreToolUseHookResult, y as ProcessToolCallsContext, R as RawToolCall, z as RunAgentActivity, C as RunAgentConfig, S as SessionEndHook, D as SessionEndHookContext, E as SessionExitReason, H as SessionLifecycleHooks, K as SessionStartHook, L as SessionStartHookContext, M as SubagentArgs, N as SubagentConfig, O as SubagentHooks, Q as SubagentInput, T as TaskCreateArgs, U as TaskGetArgs, V as TaskListArgs, W as TaskStatus, X as TaskUpdateArgs, Y as ThreadManager, Z as ThreadManagerConfig, _ as ThreadOps, $ as ToolArgs, a0 as ToolCallResult, a1 as ToolCallResultUnion, a2 as ToolDefinition, a3 as ToolHandler, a4 as ToolHandlerContext, a5 as ToolHandlerResponse, a6 as ToolHooks, a7 as ToolMap, a8 as ToolMessageContent, a9 as ToolNames, aa as ToolResult, ab as ToolResultConfig, ac as ToolRouter, ad as ToolWithHandler, ae as WorkflowTask, af as ZeitlichAgentConfig, ag as ZeitlichSession, ah as ZeitlichSharedActivities, ai as askUserQuestionTool, aj as bashTool, ak as createAgentStateManager, al as createBashToolDescription, am as createSession, an as createSharedActivities, ao as createSubagentTool, ap as createTaskCreateHandler, aq as createTaskGetHandler, ar as createTaskListHandler, as as createTaskUpdateHandler, at as createThreadManager, au as createToolRouter, av as defineSubagent, aw as defineTool, ax as editTool, ay as getStateQuery, az as globTool, aA as grepTool, aB as hasNoOtherToolCalls, aC as isTerminalStatus, aD as proxyDefaultThreadOps, aE as readTool, aF as taskCreateTool, aG as taskGetTool, aH as taskListTool, aI as taskUpdateTool, aJ as withAutoAppend, aK as writeTool } from './workflow-PjeURKw4.js';
|
|
3
3
|
import { SimplePlugin } from '@temporalio/plugin';
|
|
4
4
|
import Redis from 'ioredis';
|
|
5
5
|
import { WorkflowClient } from '@temporalio/client';
|
package/dist/index.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
import { defineQuery, proxyActivities, setHandler, uuid4, workflowInfo, executeChild } from '@temporalio/workflow';
|
|
2
2
|
import z3, { z } from 'zod';
|
|
3
3
|
import { SimplePlugin } from '@temporalio/plugin';
|
|
4
|
-
import {
|
|
4
|
+
import { mapStoredMessagesToChatMessages, AIMessage, ToolMessage, HumanMessage } from '@langchain/core/messages';
|
|
5
5
|
import crypto from 'crypto';
|
|
6
6
|
import { Context } from '@temporalio/activity';
|
|
7
7
|
import { Bash } from 'just-bash';
|
|
8
8
|
|
|
9
9
|
// src/lib/session.ts
|
|
10
|
-
var
|
|
11
|
-
function
|
|
10
|
+
var SUBAGENT_TOOL = "Subagent";
|
|
11
|
+
function buildSubagentDescription(subagents) {
|
|
12
12
|
const subagentList = subagents.map((s) => `- **${s.name}**: ${s.description}`).join("\n");
|
|
13
|
-
return `Launch a new agent to handle complex
|
|
13
|
+
return `Launch a new agent to handle complex tasks autonomously.
|
|
14
14
|
|
|
15
|
-
The ${
|
|
15
|
+
The ${SUBAGENT_TOOL} tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
|
|
16
16
|
|
|
17
17
|
Available agent types:
|
|
18
18
|
|
|
19
19
|
${subagentList}
|
|
20
20
|
|
|
21
|
-
When using the ${
|
|
21
|
+
When using the ${SUBAGENT_TOOL} tool, you must specify a subagent parameter to select which agent type to use.
|
|
22
22
|
|
|
23
23
|
Usage notes:
|
|
24
24
|
|
|
25
25
|
- Always include a short description (3-5 words) summarizing what the agent will do
|
|
26
26
|
- Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
|
|
27
|
-
- When the agent is done, it will return a single message back to you.
|
|
27
|
+
- When the agent is done, it will return a single message back to you.
|
|
28
28
|
- Each invocation starts fresh - provide a detailed task description with all necessary context.
|
|
29
29
|
- Provide clear, detailed prompts so the agent can work autonomously and return exactly the information you need.
|
|
30
30
|
- The agent's outputs should generally be trusted
|
|
31
31
|
- Clearly tell the agent what type of work you expect since it is not aware of the user's intent
|
|
32
32
|
- 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.`;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function createSubagentTool(subagents) {
|
|
35
35
|
if (subagents.length === 0) {
|
|
36
36
|
throw new Error("createTaskTool requires at least one subagent");
|
|
37
37
|
}
|
|
38
38
|
const names = subagents.map((s) => s.name);
|
|
39
39
|
return {
|
|
40
|
-
name:
|
|
41
|
-
description:
|
|
40
|
+
name: SUBAGENT_TOOL,
|
|
41
|
+
description: buildSubagentDescription(subagents),
|
|
42
42
|
schema: z3.object({
|
|
43
43
|
subagent: z3.enum(names).describe("The type of subagent to launch"),
|
|
44
44
|
description: z3.string().describe("A short (3-5 word) description of the task"),
|
|
@@ -46,7 +46,7 @@ function createTaskTool(subagents) {
|
|
|
46
46
|
})
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function createSubagentHandler(subagents) {
|
|
50
50
|
const { workflowId: parentWorkflowId, taskQueue: parentTaskQueue } = workflowInfo();
|
|
51
51
|
return async (args) => {
|
|
52
52
|
const config = subagents.find((s) => s.name === args.subagent);
|
|
@@ -65,15 +65,11 @@ function createTaskHandler(subagents) {
|
|
|
65
65
|
args: [input],
|
|
66
66
|
taskQueue: config.taskQueue ?? parentTaskQueue
|
|
67
67
|
};
|
|
68
|
-
const
|
|
69
|
-
const validated = config.resultSchema ? config.resultSchema.parse(
|
|
70
|
-
const toolResponse = typeof validated === "string" ? validated : JSON.stringify(validated, null, 2);
|
|
68
|
+
const { toolResponse, data } = typeof config.workflow === "string" ? await executeChild(config.workflow, childOpts) : await executeChild(config.workflow, childOpts);
|
|
69
|
+
const validated = config.resultSchema ? config.resultSchema.parse(data) : null;
|
|
71
70
|
return {
|
|
72
71
|
toolResponse,
|
|
73
|
-
data:
|
|
74
|
-
result: validated,
|
|
75
|
-
childWorkflowId
|
|
76
|
-
}
|
|
72
|
+
data: validated
|
|
77
73
|
};
|
|
78
74
|
};
|
|
79
75
|
}
|
|
@@ -92,9 +88,9 @@ function createToolRouter(options) {
|
|
|
92
88
|
if (s.hooks) subagentHooksMap.set(s.name, s.hooks);
|
|
93
89
|
}
|
|
94
90
|
const resolveSubagentName = (args) => args.subagent;
|
|
95
|
-
toolMap.set("
|
|
96
|
-
...
|
|
97
|
-
handler:
|
|
91
|
+
toolMap.set("Subagent", {
|
|
92
|
+
...createSubagentTool(options.subagents),
|
|
93
|
+
handler: createSubagentHandler(options.subagents),
|
|
98
94
|
...subagentHooksMap.size > 0 && {
|
|
99
95
|
hooks: {
|
|
100
96
|
onPreToolUse: async (ctx) => {
|
|
@@ -445,22 +441,16 @@ var createSession = async ({
|
|
|
445
441
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
446
442
|
stateManager.incrementTurns();
|
|
447
443
|
const currentTurn = stateManager.getTurns();
|
|
448
|
-
const { message,
|
|
444
|
+
const { message, rawToolCalls } = await runAgent({
|
|
449
445
|
threadId,
|
|
450
446
|
agentName,
|
|
451
447
|
metadata
|
|
452
448
|
});
|
|
453
|
-
if (
|
|
454
|
-
stateManager.complete();
|
|
455
|
-
exitReason = "completed";
|
|
456
|
-
return message;
|
|
457
|
-
}
|
|
458
|
-
if (!toolRouter.hasTools()) {
|
|
449
|
+
if (!toolRouter.hasTools() || rawToolCalls.length === 0) {
|
|
459
450
|
stateManager.complete();
|
|
460
451
|
exitReason = "completed";
|
|
461
452
|
return message;
|
|
462
453
|
}
|
|
463
|
-
const rawToolCalls = await threadOps.parseToolCalls(message);
|
|
464
454
|
const parsedToolCalls = [];
|
|
465
455
|
for (const tc of rawToolCalls) {
|
|
466
456
|
try {
|
|
@@ -513,8 +503,7 @@ function proxyDefaultThreadOps(options) {
|
|
|
513
503
|
return {
|
|
514
504
|
initializeThread: activities.initializeThread,
|
|
515
505
|
appendHumanMessage: activities.appendHumanMessage,
|
|
516
|
-
appendToolResult: activities.appendToolResult
|
|
517
|
-
parseToolCalls: activities.parseToolCalls
|
|
506
|
+
appendToolResult: activities.appendToolResult
|
|
518
507
|
};
|
|
519
508
|
}
|
|
520
509
|
|
|
@@ -1093,6 +1082,8 @@ function createThreadManager(config) {
|
|
|
1093
1082
|
};
|
|
1094
1083
|
return Object.assign(base, helpers);
|
|
1095
1084
|
}
|
|
1085
|
+
|
|
1086
|
+
// src/activities.ts
|
|
1096
1087
|
function createSharedActivities(redis) {
|
|
1097
1088
|
return {
|
|
1098
1089
|
async appendToolResult(config) {
|
|
@@ -1111,15 +1102,6 @@ function createSharedActivities(redis) {
|
|
|
1111
1102
|
async appendHumanMessage(threadId, content) {
|
|
1112
1103
|
const thread = createThreadManager({ redis, threadId });
|
|
1113
1104
|
await thread.appendHumanMessage(content);
|
|
1114
|
-
},
|
|
1115
|
-
async parseToolCalls(storedMessage) {
|
|
1116
|
-
const message = mapStoredMessageToChatMessage(storedMessage);
|
|
1117
|
-
const toolCalls = message.tool_calls ?? [];
|
|
1118
|
-
return toolCalls.map((toolCall) => ({
|
|
1119
|
-
id: toolCall.id,
|
|
1120
|
-
name: toolCall.name,
|
|
1121
|
-
args: toolCall.args
|
|
1122
|
-
}));
|
|
1123
1105
|
}
|
|
1124
1106
|
};
|
|
1125
1107
|
}
|
|
@@ -1157,9 +1139,14 @@ async function invokeModel({
|
|
|
1157
1139
|
}
|
|
1158
1140
|
);
|
|
1159
1141
|
await thread.append([response.toDict()]);
|
|
1142
|
+
const toolCalls = response.tool_calls ?? [];
|
|
1160
1143
|
return {
|
|
1161
1144
|
message: response.toDict(),
|
|
1162
|
-
|
|
1145
|
+
rawToolCalls: toolCalls.map((tc) => ({
|
|
1146
|
+
id: tc.id,
|
|
1147
|
+
name: tc.name,
|
|
1148
|
+
args: tc.args
|
|
1149
|
+
})),
|
|
1163
1150
|
usage: {
|
|
1164
1151
|
input_tokens: response.usage_metadata?.input_tokens,
|
|
1165
1152
|
output_tokens: response.usage_metadata?.output_tokens,
|
|
@@ -1349,6 +1336,6 @@ var toTree = async (fs, opts = {}) => {
|
|
|
1349
1336
|
return base + subtree;
|
|
1350
1337
|
};
|
|
1351
1338
|
|
|
1352
|
-
export { AGENT_HANDLER_NAMES, ZeitlichPlugin, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashHandler, createBashToolDescription, createEditHandler, createGlobHandler, createSession, createSharedActivities, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler,
|
|
1339
|
+
export { AGENT_HANDLER_NAMES, ZeitlichPlugin, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashHandler, createBashToolDescription, createEditHandler, createGlobHandler, createSession, createSharedActivities, createSubagentTool, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createThreadManager, createToolRouter, defineSubagent, defineTool, editTool, getStateQuery, globTool, grepTool, hasNoOtherToolCalls, invokeModel, isTerminalStatus, proxyDefaultThreadOps, readTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, toTree, withAutoAppend, writeTool };
|
|
1353
1340
|
//# sourceMappingURL=index.js.map
|
|
1354
1341
|
//# sourceMappingURL=index.js.map
|