agentsdk-agent 0.1.0
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/LICENSE +21 -0
- package/README.md +290 -0
- package/dist/chunk-55J6XMHW.js +3 -0
- package/dist/chunk-55J6XMHW.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +283 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
- package/src/handoff.ts +116 -0
- package/src/index.ts +9 -0
- package/src/memory.ts +62 -0
- package/src/runtime.ts +277 -0
- package/src/types.ts +101 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentSDK Agent Runtime — Types
|
|
3
|
+
* MIT License — see LICENSE. Copyright (c) 2026 Shetan Mehra.
|
|
4
|
+
*
|
|
5
|
+
* An "agent" is a model + system prompt + tools + a step loop. Each step the
|
|
6
|
+
* model may emit text or tool calls; tool calls are executed and their results
|
|
7
|
+
* fed back, until the model stops calling tools or maxSteps is reached.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
Cost,
|
|
12
|
+
Message,
|
|
13
|
+
ResolvedTool,
|
|
14
|
+
ToolCall,
|
|
15
|
+
ToolResult,
|
|
16
|
+
Usage,
|
|
17
|
+
} from 'agentsdk-core';
|
|
18
|
+
|
|
19
|
+
export type MemoryStrategy = 'none' | 'full' | 'summary' | 'window';
|
|
20
|
+
|
|
21
|
+
export interface AgentConfig {
|
|
22
|
+
/** Stable id for this agent within a graph. */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Display name. */
|
|
25
|
+
name: string;
|
|
26
|
+
/** Provider id, defaults to "glm". */
|
|
27
|
+
provider?: string;
|
|
28
|
+
/** Model id, e.g. "glm-4.6". */
|
|
29
|
+
model: string;
|
|
30
|
+
/** System prompt. */
|
|
31
|
+
systemPrompt: string;
|
|
32
|
+
/** Tools available to the agent. */
|
|
33
|
+
tools?: ResolvedTool[];
|
|
34
|
+
/** Max number of LLM round-trips before the loop is forced to stop. */
|
|
35
|
+
maxSteps?: number;
|
|
36
|
+
/** Sampling temperature. */
|
|
37
|
+
temperature?: number;
|
|
38
|
+
/** Max tokens per step. */
|
|
39
|
+
maxTokens?: number;
|
|
40
|
+
/** Enable thinking/reasoning mode if the provider supports it. */
|
|
41
|
+
thinking?: boolean;
|
|
42
|
+
/** How conversation history is carried between steps. */
|
|
43
|
+
memoryStrategy?: MemoryStrategy;
|
|
44
|
+
/** For 'window' strategy: how many most-recent messages to keep. */
|
|
45
|
+
memoryWindow?: number;
|
|
46
|
+
/** Extra provider-specific options. */
|
|
47
|
+
providerOptions?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type StepKind = 'text' | 'tool_call' | 'tool_result' | 'error';
|
|
51
|
+
|
|
52
|
+
export interface StepEvent {
|
|
53
|
+
/** 1-indexed step number. */
|
|
54
|
+
step: number;
|
|
55
|
+
kind: StepKind;
|
|
56
|
+
/** The assistant message produced at this step (if any). */
|
|
57
|
+
text?: string;
|
|
58
|
+
/** Tool calls requested by the model at this step (if any). */
|
|
59
|
+
toolCalls?: ToolCall[];
|
|
60
|
+
/** Tool results produced this step (if any). */
|
|
61
|
+
toolResults?: ToolResult[];
|
|
62
|
+
/** Error message, if kind === 'error'. */
|
|
63
|
+
error?: string;
|
|
64
|
+
/** Token usage for this step's LLM call. */
|
|
65
|
+
usage?: Usage;
|
|
66
|
+
/** Cost for this step's LLM call. */
|
|
67
|
+
cost?: Cost;
|
|
68
|
+
/** ISO timestamp. */
|
|
69
|
+
timestamp: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface AgentRunResult {
|
|
73
|
+
agentId: string;
|
|
74
|
+
/** Final text answer from the agent. */
|
|
75
|
+
text: string;
|
|
76
|
+
/** Full message history (post-run). */
|
|
77
|
+
messages: Message[];
|
|
78
|
+
/** Every step event, in order. */
|
|
79
|
+
steps: StepEvent[];
|
|
80
|
+
/** Aggregated token usage across all steps. */
|
|
81
|
+
usage: Usage;
|
|
82
|
+
/** Aggregated cost across all steps. */
|
|
83
|
+
cost: Cost;
|
|
84
|
+
/** Number of steps actually executed. */
|
|
85
|
+
stepsExecuted: number;
|
|
86
|
+
/** True if the loop hit maxSteps without a clean stop. */
|
|
87
|
+
truncated: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type StepHook = (event: StepEvent) => void | Promise<void>;
|
|
91
|
+
|
|
92
|
+
export interface AgentRunOptions {
|
|
93
|
+
/** The user/input message(s) to seed the run. */
|
|
94
|
+
messages: Message[];
|
|
95
|
+
/** Called after each step completes. */
|
|
96
|
+
onStepFinish?: StepHook;
|
|
97
|
+
/** Optional run id (auto-generated if omitted). */
|
|
98
|
+
runId?: string;
|
|
99
|
+
/** Override maxSteps for this run only. */
|
|
100
|
+
maxSteps?: number;
|
|
101
|
+
}
|