@kenkaiiii/gg-agent 5.91.2 → 5.93.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/NOTICE +1 -1
- package/README.md +112 -66
- package/package.json +18 -4
package/NOTICE
CHANGED
package/README.md
CHANGED
|
@@ -1,96 +1,142 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">@kenkaiiii/gg-agent</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<strong>
|
|
4
|
+
<strong>The agent loop: give a model tools, and it works until the job is done.</strong>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<a href="https://www.npmjs.com/package/@kenkaiiii/gg-agent"><img src="https://img.shields.io/npm/v/@kenkaiiii/gg-agent?style=for-the-badge" alt="npm version"></a>
|
|
9
|
-
<a href="
|
|
8
|
+
<a href="https://www.npmjs.com/package/@kenkaiiii/gg-agent"><img src="https://img.shields.io/npm/v/@kenkaiiii/gg-agent?style=for-the-badge&color=blue" alt="npm version"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@kenkaiiii/gg-agent"><img src="https://img.shields.io/npm/dm/@kenkaiiii/gg-agent?style=for-the-badge&color=2ecc71" alt="npm downloads per month"></a>
|
|
10
|
+
<a href="https://github.com/KenKaiii/gg-framework/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-AGPL--3.0-blue.svg?style=for-the-badge" alt="AGPL-3.0 License"></a>
|
|
10
11
|
</p>
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
gg-agent calls the model, runs the tools it asks for, sends the results back, and repeats until the model stops. It handles retries, cancellation, steering mid-run, and context that grows too long. It works with every provider in [`@kenkaiiii/gg-ai`](https://www.npmjs.com/package/@kenkaiiii/gg-ai).
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
---
|
|
15
|
+
It's the loop that runs [GG Coder](https://github.com/KenKaiii/gg-framework), a desktop coding agent.
|
|
17
16
|
|
|
18
17
|
## Install
|
|
19
18
|
|
|
20
19
|
```bash
|
|
21
|
-
npm
|
|
20
|
+
npm install @kenkaiiii/gg-agent @kenkaiiii/gg-ai zod
|
|
22
21
|
```
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
Needs Node.js 22 or newer. Ships ESM and CommonJS builds with TypeScript types.
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Agent, type AgentTool } from "@kenkaiiii/gg-agent";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
|
|
31
|
+
const WeatherParams = z.object({ city: z.string() });
|
|
32
|
+
|
|
33
|
+
const getWeather: AgentTool<typeof WeatherParams> = {
|
|
34
|
+
name: "get_weather",
|
|
35
|
+
description: "Current weather for a city",
|
|
36
|
+
parameters: WeatherParams,
|
|
37
|
+
async execute({ city }) {
|
|
38
|
+
return `22°C and sunny in ${city}`;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const agent = new Agent({
|
|
43
|
+
provider: "anthropic",
|
|
44
|
+
model: "claude-sonnet-5-5",
|
|
45
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
46
|
+
system: "You are a helpful assistant.",
|
|
47
|
+
tools: [getWeather],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Iterate for live events...
|
|
51
|
+
const run = agent.prompt("Should I pack an umbrella for Paris?");
|
|
52
|
+
for await (const event of run) {
|
|
53
|
+
if (event.type === "text_delta") process.stdout.write(event.text);
|
|
54
|
+
if (event.type === "tool_call_start") console.log(`\n→ ${event.name}`, event.args);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ...and await for the result.
|
|
58
|
+
const { message, totalTurns, totalUsage } = await run;
|
|
59
|
+
```
|
|
34
60
|
|
|
35
|
-
|
|
61
|
+
Each `prompt()` continues the same conversation. `agent.getMessages()` returns the history so you can save it, and `priorMessages` restores it later.
|
|
36
62
|
|
|
37
|
-
|
|
63
|
+
For full control without the class, `agentLoop(messages, options)` is the same loop as a plain async generator.
|
|
38
64
|
|
|
39
|
-
|
|
65
|
+
## Tools
|
|
40
66
|
|
|
41
|
-
|
|
67
|
+
A tool has a `name`, a `description`, a Zod schema for `parameters` and an `execute` function. `execute` gets the parsed arguments and a context with `signal`, `toolCallId` and `onUpdate` (for progress events).
|
|
42
68
|
|
|
43
|
-
|
|
69
|
+
- **Return** a string, or `{ content, details }` when you want to keep structured data alongside what the model sees.
|
|
70
|
+
- **Throwing is fine.** The error becomes the tool result and the model can try again or change course.
|
|
71
|
+
- **Bad arguments** are caught by the schema and returned to the model to fix.
|
|
72
|
+
- **Parallel by default.** Tool calls from one turn run together. Set `executionMode: "sequential"` on a tool that changes state, and that batch runs in order.
|
|
73
|
+
- **Timeouts.** Each tool call times out after 5 minutes; set `timeoutMs` on a tool that needs longer.
|
|
44
74
|
|
|
45
|
-
|
|
46
|
-
- `AbortSignal` support for cancellation
|
|
47
|
-
- Zod validation on tool args
|
|
48
|
-
- `maxContinuations` (default: 5) caps consecutive `pause_turn` continuations
|
|
75
|
+
## While it runs
|
|
49
76
|
|
|
50
|
-
|
|
77
|
+
| Method | What it does |
|
|
78
|
+
| ---------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
79
|
+
| `agent.steer(message)` | Add a message mid-run. Running tools that can be interrupted stop, and the model sees it next turn |
|
|
80
|
+
| `agent.followUp(message)` | Queue a message for when the agent would otherwise stop |
|
|
81
|
+
| `signal` (`AbortController`) | Stop the run. Call `agent.setSignal()` with a fresh signal before the next prompt |
|
|
51
82
|
|
|
52
83
|
## Events
|
|
53
84
|
|
|
54
|
-
| Event
|
|
55
|
-
|
|
|
56
|
-
| `text_delta`
|
|
57
|
-
| `thinking_delta`
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
| Event | When |
|
|
86
|
+
| ----------------------- | ------------------------------------------------------------- |
|
|
87
|
+
| `text_delta` | New text |
|
|
88
|
+
| `thinking_delta` | New reasoning text |
|
|
89
|
+
| `toolcall_delta` | Tool call arguments as they stream in |
|
|
90
|
+
| `tool_call_start` | A tool started (`name`, `args`) |
|
|
91
|
+
| `tool_call_update` | Progress from a running tool |
|
|
92
|
+
| `tool_call_end` | A tool finished (`result`, `isError`, `durationMs`) |
|
|
93
|
+
| `server_tool_call` | The provider ran a server-side tool |
|
|
94
|
+
| `server_tool_result` | Result of that server-side tool |
|
|
95
|
+
| `steering_message` | A steering message was added |
|
|
96
|
+
| `follow_up_message` | A follow-up message was added |
|
|
97
|
+
| `retry` | A failed model call is being retried |
|
|
98
|
+
| `turn_end` | One model call finished (`stopReason`, `usage`, `timing`) |
|
|
99
|
+
| `checkpoint` | A safe point to save the conversation |
|
|
100
|
+
| `truncated` | A turn ended early (output limit, refusal, provider error) |
|
|
101
|
+
| `max_turns` | The turn limit was reached before the model finished |
|
|
102
|
+
| `turn_budget_extended` | `onTurnBudgetExhausted` granted more turns |
|
|
103
|
+
| `stream_rule_triggered` | A `streamRules` pattern matched and the step is being retried |
|
|
104
|
+
| `agent_done` | Finished (`totalTurns`, `totalUsage`) |
|
|
105
|
+
| `error` | The run failed |
|
|
68
106
|
|
|
69
107
|
## Options
|
|
70
108
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `maxContinuations`
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
109
|
+
Every [`stream()` option from gg-ai](https://www.npmjs.com/package/@kenkaiiii/gg-ai) that makes sense per call (`apiKey`, `baseUrl`, `thinking`, `maxTokens`, `temperature`, `cacheRetention`, `webSearch`, `providerOptions`, `fetch` and so on) is passed through. On top of those:
|
|
110
|
+
|
|
111
|
+
| Option | Type | What it does |
|
|
112
|
+
| ----------------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
113
|
+
| `provider` | `Provider` | **Required.** Any gg-ai provider |
|
|
114
|
+
| `model` | `string` | **Required.** |
|
|
115
|
+
| `system` | `string` | System prompt |
|
|
116
|
+
| `tools` | `AgentTool[]` | Your tools |
|
|
117
|
+
| `priorMessages` | `Message[]` | Conversation to resume from |
|
|
118
|
+
| `maxTurns` | `number` | Model calls per run (default 300) |
|
|
119
|
+
| `onTurnBudgetExhausted` | `(ctx) => boolean \| Promise<boolean>` | Return true to grant more turns when the limit is hit mid-task |
|
|
120
|
+
| `transformContext` | `(messages, options) => Message[]` | Runs before every model call: trim, summarize or add context. `options.force` means the provider reported the context is full |
|
|
121
|
+
| `resolveCredentials` | `() => Promise<{ apiKey }>` | Fetch a fresh key or token each turn, so long runs survive token refreshes |
|
|
122
|
+
| `resolveTool` | `(name) => AgentTool \| undefined` | Load a tool on demand when the model calls one you haven't passed yet |
|
|
123
|
+
| `maxToolResultChars` | `number` | Cut any single tool result longer than this |
|
|
124
|
+
| `streamRules` | `StreamRulesConfig` | Regex rules on streamed output; a match discards the step and retries with a reminder |
|
|
125
|
+
| `maxContinuations` | `number` | Limit on back-to-back `pause_turn` continuations (default 5) |
|
|
126
|
+
|
|
127
|
+
The full list is the `AgentOptions` type.
|
|
128
|
+
|
|
129
|
+
## The GG Framework
|
|
130
|
+
|
|
131
|
+
| Package | What it does |
|
|
132
|
+
| ---------------------------------------------------------------------- | ----------------------------------------------------------------- |
|
|
133
|
+
| [@kenkaiiii/gg-ai](https://www.npmjs.com/package/@kenkaiiii/gg-ai) | One streaming API for every provider |
|
|
134
|
+
| **@kenkaiiii/gg-agent** | The agent loop (this package) |
|
|
135
|
+
| [@kenkaiiii/gg-core](https://www.npmjs.com/package/@kenkaiiii/gg-core) | Model list, sign-in and stored credentials, local model discovery |
|
|
136
|
+
| [@kenkaiiii/ggcoder](https://www.npmjs.com/package/@kenkaiiii/ggcoder) | The GG Coder coding agent: CLI, tools and sessions |
|
|
137
|
+
|
|
138
|
+
Source, issues and the desktop app: [github.com/KenKaiii/gg-framework](https://github.com/KenKaiii/gg-framework).
|
|
93
139
|
|
|
94
140
|
## License
|
|
95
141
|
|
|
96
|
-
AGPL-3.0-only
|
|
142
|
+
[AGPL-3.0-only](https://github.com/KenKaiii/gg-framework/blob/main/LICENSE). You can build on it; if you distribute your changes or run them as a network service, share their source under the same license.
|
package/package.json
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenkaiiii/gg-agent",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.93.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Agent loop for LLMs: runs your tools, feeds results back and loops until done, with retries, steering and cancellation. Works with every gg-ai provider.",
|
|
6
|
+
"author": "Ken Kai",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"llm",
|
|
9
|
+
"ai",
|
|
10
|
+
"agent",
|
|
11
|
+
"agent-loop",
|
|
12
|
+
"tool-calling",
|
|
13
|
+
"anthropic",
|
|
14
|
+
"openai"
|
|
15
|
+
],
|
|
6
16
|
"license": "AGPL-3.0-only",
|
|
7
17
|
"engines": {
|
|
8
18
|
"node": ">=22"
|
|
9
19
|
},
|
|
10
20
|
"repository": {
|
|
11
21
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/
|
|
22
|
+
"url": "git+https://github.com/KenKaiii/gg-framework.git",
|
|
13
23
|
"directory": "packages/gg-agent"
|
|
14
24
|
},
|
|
25
|
+
"homepage": "https://github.com/KenKaiii/gg-framework/tree/main/packages/gg-agent#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/KenKaiii/gg-framework/issues"
|
|
28
|
+
},
|
|
15
29
|
"exports": {
|
|
16
30
|
".": {
|
|
17
31
|
"types": "./dist/index.d.ts",
|
|
@@ -28,7 +42,7 @@
|
|
|
28
42
|
],
|
|
29
43
|
"dependencies": {
|
|
30
44
|
"zod": "^4.5.4",
|
|
31
|
-
"@kenkaiiii/gg-ai": "5.
|
|
45
|
+
"@kenkaiiii/gg-ai": "5.93.0"
|
|
32
46
|
},
|
|
33
47
|
"devDependencies": {
|
|
34
48
|
"typescript": "^6.0.3",
|