2025-12-02 10:59:09 +00:00
# @push.rocks/smartagent
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
A lightweight agentic loop built on **Vercel AI SDK v6 ** via `@push.rocks/smartai` . Register tools, get a model, call `runAgent()` — done. 🚀
2025-12-02 10:59:09 +00:00
## Install
2025-12-15 14:49:26 +00:00
2025-12-02 10:59:09 +00:00
```bash
pnpm install @push .rocks/smartagent
```
2025-12-15 14:49:26 +00:00
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/ ](https://community.foss.global/ ). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/ ](https://code.foss.global/ ) account to submit Pull Requests directly.
2025-12-02 10:59:09 +00:00
## Overview
2026-03-06 11:39:01 +00:00
`@push.rocks/smartagent` wraps the AI SDK's `streamText` with `stopWhen: stepCountIs(n)` for **parallel multi-step tool execution ** . No classes to instantiate, no lifecycle to manage — just one async function:
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
```typescript
import { runAgent, tool, z } from '@push .rocks/smartagent';
import { getModel } from '@push .rocks/smartai';
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
const model = getModel({
provider: 'anthropic',
model: 'claude-sonnet-4-5-20250929',
apiKey: process.env.ANTHROPIC_TOKEN,
});
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
const result = await runAgent({
model,
prompt: 'What is 7 + 35?',
system: 'You are a helpful assistant. Use tools when asked.',
tools: {
calculator: tool({
description: 'Perform arithmetic',
inputSchema: z.object({
operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
a: z.number(),
b: z.number(),
}),
execute: async ({ operation, a, b }) => {
const ops = { add: a + b, subtract: a - b, multiply: a * b, divide: a / b };
return String(ops[operation]);
},
}),
},
maxSteps: 10,
});
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
console.log(result.text); // "7 + 35 = 42"
console.log(result.steps); // number of agentic steps taken
console.log(result.usage); // { promptTokens, completionTokens, totalTokens }
```
2025-12-02 10:59:09 +00:00
## Architecture
```
2026-03-06 11:39:01 +00:00
┌─────────────────────────────────────────────────┐
│ runAgent({ model, prompt, tools, maxSteps }) │
│ │
2026-03-06 11:41:30 +00:00
│ ┌────────────┐ ┌───────────┐ ┌───────────┐ │
│ │ Messages │──▶│ streamText│──▶│ Tools │ │
│ │ (history) │◀──│ (AI SDK) │◀──│ (ToolSet) │ │
│ └────────────┘ └───────────┘ └───────────┘ │
2026-03-06 11:39:01 +00:00
│ │
│ stopWhen: stepCountIs(maxSteps) │
│ + retry with backoff on 429/529/503 │
│ + context overflow detection & recovery │
│ + tool call repair (case-insensitive matching) │
└─────────────────────────────────────────────────┘
2025-12-02 10:59:09 +00:00
```
2026-03-06 11:39:01 +00:00
**Key features:**
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
- 🔄 **Multi-step agentic loop ** — the model calls tools, sees results, and continues reasoning until done
- ⚡ **Parallel tool execution ** — multiple tool calls in a single step are executed concurrently
- 🔧 **Auto-retry with backoff ** — handles 429/529/503 errors with header-aware retry delays
- 🩹 **Tool call repair ** — case-insensitive name matching + invalid tool sink prevents crashes
- 📊 **Token streaming ** — `onToken` and `onToolCall` callbacks for real-time progress
- 💥 **Context overflow handling ** — detects overflow and invokes your `onContextOverflow` callback
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
## Core API
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
### `runAgent(options): Promise<IAgentRunResult>`
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
The single entry point. Options:
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `model` | `LanguageModelV3` | * required * | Model from `@push.rocks/smartai` 's `getModel()` |
| `prompt` | `string` | * required * | The user's task/question |
| `system` | `string` | `undefined` | System prompt |
| `tools` | `ToolSet` | `{}` | Tools the agent can call |
| `maxSteps` | `number` | `20` | Max agentic steps before stopping |
| `messages` | `ModelMessage[]` | `[]` | Conversation history (for multi-turn) |
| `maxRetries` | `number` | `5` | Max retries on rate-limit/server errors |
| `onToken` | `(delta: string) => void` | — | Streaming token callback |
| `onToolCall` | `(name: string) => void` | — | Called when a tool is invoked |
| `onContextOverflow` | `(messages) => messages` | — | Handle context overflow (e.g., compact messages) |
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
### `IAgentRunResult`
2025-12-15 14:49:26 +00:00
```typescript
2026-03-06 11:39:01 +00:00
interface IAgentRunResult {
text: string; // Final response text
finishReason: string; // 'stop', 'tool-calls', 'length', etc.
steps: number; // Number of agentic steps taken
messages: ModelMessage[]; // Full conversation for multi-turn
usage: {
promptTokens: number;
completionTokens: number;
totalTokens: number;
};
}
2025-12-15 14:49:26 +00:00
```
2026-03-06 11:39:01 +00:00
## Defining Tools 🛠️
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
Tools use Vercel AI SDK's `tool()` helper with Zod schemas:
2025-12-02 10:59:09 +00:00
```typescript
2026-03-06 11:39:01 +00:00
import { tool, z } from '@push .rocks/smartagent';
const myTool = tool({
description: 'Describe what this tool does',
inputSchema: z.object({
param1: z.string().describe('What this parameter is for'),
param2: z.number().optional(),
}),
execute: async ({ param1, param2 }) => {
// Do work, return a string
return `Result: ${param1}` ;
},
});
2025-12-02 10:59:09 +00:00
```
2026-03-06 11:39:01 +00:00
Pass tools as a flat object to `runAgent()` :
2025-12-02 10:59:09 +00:00
```typescript
2026-03-06 11:39:01 +00:00
await runAgent({
model,
prompt: 'Do the thing',
tools: { myTool, anotherTool },
maxSteps: 10,
});
2025-12-02 10:59:09 +00:00
```
2026-03-06 11:39:01 +00:00
## ToolRegistry
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
A lightweight helper for collecting tools:
2025-12-02 10:59:09 +00:00
```typescript
2026-03-06 11:39:01 +00:00
import { ToolRegistry, tool, z } from '@push .rocks/smartagent';
const registry = new ToolRegistry();
registry.register('random_number', tool({
description: 'Generate a random integer between min and max',
inputSchema: z.object({
min: z.number(),
max: z.number(),
}),
execute: async ({ min, max }) => {
return String(Math.floor(Math.random() * (max - min + 1)) + min);
},
}));
registry.register('is_even', tool({
description: 'Check if a number is even',
inputSchema: z.object({ number: z.number() }),
execute: async ({ number: n }) => n % 2 === 0 ? 'Yes' : 'No',
}));
const result = await runAgent({
model,
prompt: 'Generate a random number and tell me if it is even',
tools: registry.getTools(),
maxSteps: 10,
});
2025-12-02 10:59:09 +00:00
```
2026-03-06 11:39:01 +00:00
## Built-in Tool Factories 🧰
2025-12-02 12:11:31 +00:00
2026-03-06 11:39:01 +00:00
Import from the `@push.rocks/smartagent/tools` subpath:
2025-12-02 12:11:31 +00:00
```typescript
2026-03-06 11:39:01 +00:00
import { filesystemTool, shellTool, httpTool, jsonTool } from '@push .rocks/smartagent/tools';
2025-12-02 12:11:31 +00:00
```
2026-03-06 11:39:01 +00:00
### `filesystemTool(options?)`
2026-01-20 01:30:26 +00:00
2026-03-06 11:39:01 +00:00
Returns: `read_file` , `write_file` , `list_directory` , `delete_file`
2026-01-20 01:30:26 +00:00
2026-01-20 12:01:07 +00:00
```typescript
2026-03-06 11:39:01 +00:00
const tools = filesystemTool({ rootDir: '/home/user/workspace' });
2026-01-20 12:01:07 +00:00
2026-03-06 11:39:01 +00:00
await runAgent({
model,
prompt: 'Create a file called hello.txt with "Hello World"',
tools,
maxSteps: 5,
});
2026-01-20 01:30:26 +00:00
```
2026-03-06 11:39:01 +00:00
Options:
- `rootDir` — restrict all file operations to this directory. Paths outside it throw `Access denied` .
2026-01-20 14:39:34 +00:00
2026-03-06 11:39:01 +00:00
### `shellTool(options?)`
2026-01-20 14:39:34 +00:00
2026-03-06 11:39:01 +00:00
Returns: `run_command`
2026-01-20 14:39:34 +00:00
```typescript
2026-03-06 11:39:01 +00:00
const tools = shellTool({ cwd: '/tmp', allowedCommands: ['ls', 'echo', 'cat'] });
2026-01-20 14:39:34 +00:00
2026-03-06 11:39:01 +00:00
await runAgent({
model,
prompt: 'List all files in /tmp',
tools,
maxSteps: 5,
2026-01-20 14:39:34 +00:00
});
```
2026-03-06 11:39:01 +00:00
Options:
- `cwd` — working directory for commands
- `allowedCommands` — whitelist of allowed commands (if set, others are rejected)
2026-01-20 14:39:34 +00:00
2026-03-06 11:39:01 +00:00
### `httpTool()`
2026-01-20 14:39:34 +00:00
2026-03-06 11:39:01 +00:00
Returns: `http_get` , `http_post`
2026-01-20 14:39:34 +00:00
```typescript
2026-03-06 11:39:01 +00:00
const tools = httpTool();
2026-01-20 14:39:34 +00:00
2026-03-06 11:39:01 +00:00
await runAgent({
model,
prompt: 'Fetch the data from https://api.example.com/status',
tools,
maxSteps: 5,
2026-01-20 14:39:34 +00:00
});
```
2026-03-06 11:39:01 +00:00
### `jsonTool()`
2026-01-20 01:30:26 +00:00
2026-03-06 11:39:01 +00:00
Returns: `json_validate` , `json_transform`
2026-01-20 01:30:26 +00:00
```typescript
2026-03-06 11:39:01 +00:00
const tools = jsonTool();
// Direct usage:
const result = await tools.json_validate.execute({
jsonString: '{"name":"test","value":42}',
requiredFields: ['name', 'value'],
2026-01-20 01:30:26 +00:00
});
2026-03-06 11:39:01 +00:00
// → "Valid JSON: object with 2 keys"
2026-01-20 01:30:26 +00:00
```
2026-03-06 11:39:01 +00:00
## Streaming & Callbacks 🎥
2026-01-20 01:30:26 +00:00
2026-03-06 11:39:01 +00:00
Monitor the agent in real-time:
2026-01-20 01:30:26 +00:00
```typescript
2026-03-06 11:39:01 +00:00
const result = await runAgent({
model,
prompt: 'Analyze this data...',
tools,
maxSteps: 10,
2026-01-20 01:30:26 +00:00
2026-03-06 11:39:01 +00:00
// Token-by-token streaming
onToken: (delta) => process.stdout.write(delta),
2026-01-20 01:30:26 +00:00
2026-03-06 11:39:01 +00:00
// Tool call notifications
onToolCall: (toolName) => console.log(`\n🔧 Calling: ${toolName}` ),
});
2026-01-20 01:30:26 +00:00
```
2026-03-06 11:39:01 +00:00
## Context Overflow Handling 💥
2026-01-20 01:30:26 +00:00
2026-03-06 11:39:01 +00:00
For long-running agents that might exceed the model's context window, use the compaction subpath:
2026-01-20 01:30:26 +00:00
```typescript
2026-03-06 11:39:01 +00:00
import { runAgent } from '@push .rocks/smartagent';
import { compactMessages } from '@push .rocks/smartagent/compaction';
const result = await runAgent({
model,
prompt: 'Process all 500 files...',
tools,
maxSteps: 100,
onContextOverflow: async (messages) => {
// Summarize the conversation to free up context space
return await compactMessages(model, messages);
2026-01-20 01:30:26 +00:00
},
});
```
2026-03-06 11:39:01 +00:00
## Output Truncation ✂️
2026-01-20 12:01:07 +00:00
2026-03-06 11:39:01 +00:00
Prevent large tool outputs from consuming too much context:
2026-01-20 12:01:07 +00:00
```typescript
2026-03-06 11:39:01 +00:00
import { truncateOutput } from '@push .rocks/smartagent';
2026-01-20 12:01:07 +00:00
2026-03-06 11:39:01 +00:00
const { content, truncated, notice } = truncateOutput(hugeOutput, {
maxLines: 2000, // default
maxBytes: 50_000, // default
2026-01-20 12:01:07 +00:00
});
```
2026-03-06 11:39:01 +00:00
The built-in tool factories use `truncateOutput` internally.
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
## Multi-Turn Conversations 💬
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
Pass the returned `messages` back for multi-turn interactions:
2025-12-02 10:59:09 +00:00
```typescript
2026-03-06 11:39:01 +00:00
// First turn
const turn1 = await runAgent({
model,
prompt: 'Create a project structure',
tools,
maxSteps: 10,
});
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
// Second turn — continues the conversation
const turn2 = await runAgent({
model,
prompt: 'Now add a README to the project',
tools,
maxSteps: 10,
messages: turn1.messages, // pass history
2025-12-15 14:49:26 +00:00
});
2026-03-06 11:39:01 +00:00
```
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
## Exports
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
### Main (`@push.rocks/smartagent`)
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
| Export | Type | Description |
|--------|------|-------------|
| `runAgent` | function | Core agentic loop |
| `ToolRegistry` | class | Tool collection helper |
| `truncateOutput` | function | Output truncation utility |
| `ContextOverflowError` | class | Error type for context overflow |
| `tool` | function | Re-exported from `@push.rocks/smartai` |
| `z` | object | Re-exported Zod for schema definitions |
| `stepCountIs` | function | Re-exported from AI SDK |
| `jsonSchema` | function | Re-exported from `@push.rocks/smartai` |
2025-12-02 10:59:09 +00:00
2026-03-06 11:39:01 +00:00
### Tools (`@push.rocks/smartagent/tools`)
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
| Export | Type | Description |
|--------|------|-------------|
| `filesystemTool` | factory | File operations (read, write, list, delete) |
| `shellTool` | factory | Shell command execution |
| `httpTool` | factory | HTTP GET/POST requests |
| `jsonTool` | factory | JSON validation and transformation |
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
### Compaction (`@push.rocks/smartagent/compaction`)
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
| Export | Type | Description |
|--------|------|-------------|
| `compactMessages` | function | Summarize message history to free context |
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
## Dependencies
2025-12-15 14:49:26 +00:00
2026-03-06 11:39:01 +00:00
- **[`@push.rocks/smartai` ](https://code.foss.global/push.rocks/smartai )** — Provider registry, `getModel()` , re-exports `tool` /`jsonSchema`
- **[`ai` ](https://www.npmjs.com/package/ai )** v6 — Vercel AI SDK (`streamText` , `stepCountIs` , `ModelMessage` )
- **[`zod` ](https://www.npmjs.com/package/zod )** — Tool input schema definitions
- **[`@push.rocks/smartfs` ](https://code.foss.global/push.rocks/smartfs )** — Filesystem tool implementation
- **[`@push.rocks/smartshell` ](https://code.foss.global/push.rocks/smartshell )** — Shell tool implementation
- **[`@push.rocks/smartrequest` ](https://code.foss.global/push.rocks/smartrequest )** — HTTP tool implementation
2025-12-02 10:59:09 +00:00
## License and Legal Information
2025-12-15 14:49:26 +00:00
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE ](./LICENSE ) file.
2025-12-02 10:59:09 +00:00
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
2025-12-15 14:49:26 +00:00
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
2025-12-02 10:59:09 +00:00
### Company Information
2026-01-20 01:30:26 +00:00
Task Venture Capital GmbH
2025-12-15 14:49:26 +00:00
Registered at District Court Bremen HRB 35230 HB, Germany
2025-12-02 10:59:09 +00:00
2025-12-15 14:49:26 +00:00
For any legal inquiries or further information, please contact us via email at hello@task .vc.
2025-12-02 10:59:09 +00:00
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.