agent-accelerator 0.5.8 → 0.6.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.
Files changed (67) hide show
  1. package/README.md +26 -5
  2. package/examples/prompts/SYSTEM_PROMPT.md +2 -0
  3. package/examples/prompts/SYSTEM_PROMPT_AGENT.md +4 -0
  4. package/examples/prompts/SYSTEM_PROMPT_TOOLS.md +1 -0
  5. package/package.json +4 -1
  6. package/src/agent/agent.ts +374 -167
  7. package/src/agent/architecture.md +14 -12
  8. package/src/agent/config-blocks.ts +39 -12
  9. package/src/agent/context.ts +8 -3
  10. package/src/agent/delegation.ts +82 -29
  11. package/src/agent/loop.ts +449 -373
  12. package/src/agent/subagent.ts +1 -3
  13. package/src/agent/subagents-tool.ts +45 -7
  14. package/src/agent/subagents.md +3 -0
  15. package/src/agent/turns.ts +3 -1
  16. package/src/agent/worker.ts +58 -28
  17. package/src/agent/workers.ts +113 -20
  18. package/src/architecture.md +16 -15
  19. package/src/index.ts +34 -10
  20. package/src/models/architecture.md +4 -3
  21. package/src/models/catalog-cache.ts +6 -5
  22. package/src/models/catalog.ts +46 -49
  23. package/src/providers/architecture.md +10 -8
  24. package/src/providers/google.ts +150 -62
  25. package/src/providers/openai-compat.ts +60 -58
  26. package/src/providers/openai.ts +57 -39
  27. package/src/providers/openrouter.ts +87 -32
  28. package/src/providers/registry.ts +12 -26
  29. package/src/providers/shared.ts +89 -39
  30. package/src/providers.ts +56 -115
  31. package/src/scheduler/architecture.md +9 -8
  32. package/src/scheduler/scheduled-actions.md +4 -0
  33. package/src/scheduler/scheduler.ts +186 -60
  34. package/src/scheduler/store.ts +23 -10
  35. package/src/scheduler/time.ts +17 -3
  36. package/src/scheduler/tool.ts +33 -7
  37. package/src/session/architecture.md +7 -6
  38. package/src/session/journal.ts +38 -12
  39. package/src/session/store.ts +122 -61
  40. package/src/session/usage.ts +58 -9
  41. package/src/streaming/architecture.md +4 -3
  42. package/src/streaming/event-stream.ts +26 -12
  43. package/src/telemetry.ts +6 -2
  44. package/src/tools/architecture.md +8 -7
  45. package/src/tools/executor.ts +50 -48
  46. package/src/tools/schema.ts +10 -6
  47. package/src/tools/subagent-result.ts +6 -1
  48. package/src/tools/tool.ts +9 -11
  49. package/src/types/agent.ts +2 -21
  50. package/src/types/architecture.md +11 -10
  51. package/src/types/core.ts +1 -9
  52. package/src/types/errors.ts +26 -4
  53. package/src/types/model.ts +0 -4
  54. package/src/types/tool.ts +12 -2
  55. package/src/update-models.ts +5 -5
  56. package/src/utils/architecture.md +16 -15
  57. package/src/utils/cache.ts +1 -3
  58. package/src/utils/durable.ts +17 -5
  59. package/src/utils/env.ts +9 -7
  60. package/src/utils/errors.ts +50 -44
  61. package/src/utils/headers.ts +3 -10
  62. package/src/utils/media.ts +23 -8
  63. package/src/utils/raw-capture.ts +9 -2
  64. package/src/utils/retry.ts +17 -31
  65. package/src/utils/safe-io.ts +29 -7
  66. package/src/utils/serialization.ts +1 -4
  67. package/src/utils/session.ts +1 -2
package/README.md CHANGED
@@ -126,7 +126,7 @@ An `Agent` holds:
126
126
  | `cache` | `CacheOption` | `"implicit" \| "5m" \| "30m" \| "1h" \| "12h"`. Prompt-cache lifetime; unsupported values warn and fall back (see [Cache](#cache)). |
127
127
  | `serviceTier` | `"flex" \| "priority"` | Cost / priority routing where supported. Omit for standard routing. |
128
128
  | `maxTurns` | `number` | Maximum model → tool → model loops per `run`. Infinite by default (`0` or omitted = no limit). Hitting a finite limit with pending tool calls warns and sets `finishReason: "max_turns"`. |
129
- | `limits` | `AgentRunLimits` | `{ maxTurns?, deadlineMs?, maxToolCallsPerRun?, maxTotalTokens?, requestTimeoutMs?, firstByteTimeoutMs?, streamIdleTimeoutMs? }`. The first four are unlimited by default. The three network timeouts default to 300 s / 120 s / 300 s so a silent connection fails instead of hanging; set one to `0` or `Infinity` to turn it off. A timeout raises a retryable `TimeoutError`. See [Safety and operations](docs/guides/safety-and-ops.md#network-timeouts). |
129
+ | `limits` | `AgentRunLimits` | `{ maxTurns?, deadlineMs?, maxToolCallsPerRun?, maxTotalTokens?, requestTimeoutMs?, firstByteTimeoutMs?, streamIdleTimeoutMs? }`. The first four are unlimited by default; hitting `maxTurns` ends the run with `finishReason: "max_turns"`, the other three throw a `BudgetExceededError`. The three network timeouts default to 300 s / 120 s / 300 s so a silent connection fails instead of hanging; set one to `0` or `Infinity` to turn it off. A timeout raises a retryable `TimeoutError`. See [Safety and operations](docs/guides/safety-and-ops.md#network-timeouts). |
130
130
  | `budget` | `Budget` | `{ maxCostUsd?, maxTotalTokens?, maxDurationMs?, maxTotalSubagents? }`, per run, workers included. Unlimited by default; exceeding it throws `BudgetExceededError` with partial usage. |
131
131
  | `sessionId` | `string` | Stable identifier used for cache affinity. Auto-generated when omitted. |
132
132
  | `headers` | `Record<string,string>` | Additional headers merged into every request. |
@@ -720,7 +720,7 @@ It also:
720
720
  * maps `tool_choice` (`auto` omitted; `none`, `required`, and function pins supported);
721
721
  * treats an error chunk inside a stream (HTTP 200) like an HTTP error: its status comes from the chunk's `code`, or from its `error_type` (`rate_limit_exceeded` 429, `provider_overloaded` 503, `provider_unavailable` 502, `timeout` 504, `server` 500), so `runRetries` retries the retryable ones;
722
722
  * reports `cached_tokens` / `cache_write_tokens` / reasoning tokens, preferring provider-reported `cost` when present (a reported `0`, a free model or a cache hit, stays a known `$0`);
723
- * accepts `anthropic/...` and `~anthropic/...` model names for the `5m` / `1h` cache setting, and sends at most 4 `stop` sequences (the Chat Completions maximum; extra ones are dropped with one `provider_warning`).
723
+ * accepts `anthropic/...` and `~anthropic/...` model names for the `5m` / `1h` cache setting.
724
724
 
725
725
  `serviceTier` values other than `flex` / `priority` are omitted (standard routing).
726
726
 
@@ -1089,16 +1089,35 @@ Credential headers are always redacted (`Authorization`, `x-goog-api-key`, anyth
1089
1089
  ---
1090
1090
  ## Errors
1091
1091
 
1092
- Provider failures throw `AgentAccelProviderError` — one actionable line,
1092
+ Provider failures throw a `ProviderError` — one actionable line,
1093
1093
  never a wire dump:
1094
1094
 
1095
1095
  ```text
1096
1096
  [openrouter/nvidia/nemotron-3.5-lightning:free] request failed (404): No endpoints found that support input video
1097
1097
  ```
1098
1098
 
1099
- Raw details (`statusCode`, `url`, truncated body) stay attached as
1099
+ Branch on the class and `err.retryable` (true for HTTP 408/425/429/5xx,
1100
+ network errors and a cut stream), never on the message:
1101
+
1102
+ ```ts
1103
+ import { ProviderError, TimeoutError } from "agent-accelerator";
1104
+
1105
+ try {
1106
+ await agent.run("...");
1107
+ } catch (err) {
1108
+ if (err instanceof ProviderError && err.retryable) retryLater(); // e.g. a 429 or 503
1109
+ else if (err instanceof TimeoutError) retryLater(); // a request / first-byte / idle timeout
1110
+ else throw err;
1111
+ }
1112
+ ```
1113
+
1114
+ `err.code` is the SDK kind (`"provider"`, `"incomplete_stream"` for a cut
1115
+ stream; `"timeout"`, `"config"`, ... on the other classes); the provider's own
1116
+ error code (e.g. `"not_found"`, `"rate_limit_exceeded"`) is `err.providerCode`.
1117
+ Raw details (`statusCode`, `url`, truncated body, `providerCode`) stay attached as
1100
1118
  non-enumerable properties: available programmatically, invisible in runtime
1101
- dumps. URL query strings are stripped (keys sometimes live there); headers
1119
+ dumps. Input a model cannot take (a modality the catalog says it lacks, video on
1120
+ the OpenAI Responses wire) fails before the network with a `ValidationError`. URL query strings are stripped (keys sometimes live there); headers
1102
1121
  and cookies are never attached. Helpers:
1103
1122
 
1104
1123
  * `toConciseProviderError(err, providerId, modelId)` — collapse any provider error.
@@ -1433,6 +1452,8 @@ saveSessionFile(".session.json", agent, telemetry);
1433
1452
 
1434
1453
  ```bash
1435
1454
  bun run typecheck # tsc --noEmit
1455
+ bun run lint # Biome: unused code is an error, `any` a warning
1456
+ bun run format # Biome formatter (120 columns); `biome format src examples` only checks
1436
1457
  bun test # bun test test/
1437
1458
  bun run update-models # refresh model catalog cache (supports --force, --ttl=24h)
1438
1459
  ```
@@ -1,12 +1,14 @@
1
1
  You are **Agent Accelerator**, an expert, high-performance AI assistant.
2
2
 
3
3
  ### Operational Directives
4
+
4
5
  - **Direct Execution**: Be concise, direct, and factual. Use structured Markdown (headings, lists, tables) for clarity.
5
6
  - **Thinking Traces**: When reasoning is enabled, think methodically before concluding. Keep final answers synthesized and free of raw thinking artifacts.
6
7
  - **File Discipline**: Always inspect/read target files before editing; perform surgical, minimal modifications. State absolute or workspace-relative paths clearly.
7
8
  - **Code & Shell Quality**: Prefer idiomatic, type-safe solutions. Avoid destructive operations unless explicitly requested.
8
9
 
9
10
  ### Tool-Calling Protocols
11
+
10
12
  - **Strict Schema Conformance**: Adhere strictly to the tool's parameter schema. Never invent, hallucinate, or pass unrecognized arguments.
11
13
  - **Parallel Dispatch**: When multiple tool calls are independent, batch and execute them simultaneously in a single turn.
12
14
  - **No Narration**: Invoke tools immediately. Do not announce or narrate tool invocations beforehand (e.g., avoid "I will now read...").
@@ -1,6 +1,7 @@
1
1
  You are an Agent — you evaluate user objectives and decide whether to solve them directly or delegate to specialized parallel workers with the `subagents` tool.
2
2
 
3
3
  ### Workflow & Decision Matrix
4
+
4
5
  1. **Triage**:
5
6
  - Single-focus, factual, code-generation, or conversational prompts → Answer directly, concisely, and completely.
6
7
  - Do NOT start workers for trivial, single-step tasks.
@@ -13,10 +14,12 @@ You are an Agent — you evaluate user objectives and decide whether to solve th
13
14
  - `task`: Focused, non-overlapping research query or execution directive.
14
15
  3. **Aggregate**:
15
16
  - Each worker answers with a header line and its findings:
17
+
16
18
  ```
17
19
  [worker market-analyst-1a2b3c4d] replied:
18
20
  Findings from the worker
19
21
  ```
22
+
20
23
  - Use `command: "message"` with the worker's `id` to ask a follow-up; the worker remembers the conversation. `command: "close"` when you no longer need it.
21
24
  4. **Synthesize**:
22
25
  - Deliver an editorial-grade, cohesive report that integrates all worker insights.
@@ -24,5 +27,6 @@ You are an Agent — you evaluate user objectives and decide whether to solve th
24
27
  - Structure with executive summaries, comparative Markdown tables, and concrete strategic conclusions. Never present an uncurated list of worker summaries.
25
28
 
26
29
  ### Execution Rules
30
+
27
31
  - **Tool Protocol**: Call `subagents` directly without conversational preambles. Start parallel workers with several `spawn` calls in one turn.
28
32
  - **Context Isolation**: Workers start blank; provide complete background in their `instructions` and `task`.
@@ -1,6 +1,7 @@
1
1
  You are a precise, tool-equipped AI agent engineered for accurate execution and high-efficiency operations.
2
2
 
3
3
  ### Tool Invocation Protocols
4
+
4
5
  - **Intent Verification**: Evaluate whether tool execution is necessary. If the query is conversational or already answerable with existing context, answer directly.
5
6
  - **Strict Schema Adherence**: Validate all arguments against the declared JSON schema before calling. Never invent parameters, omit required properties, or pass invalid types.
6
7
  - **Parallel Dispatch**: Whenever multiple tool operations are independent (e.g., multi-file reads, batch queries, concurrent searches), invoke all tool calls concurrently in a single turn.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-accelerator",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "description": "High-performance SDK for AI agents with a unified API across AI providers. Optimized for high cache hit rates, observability, and seamless agent orchestration. Built to power production-grade agentic systems and harnesses for teams at any scale.",
5
5
  "license": "MIT",
6
6
  "author": "Sashvat Bharat",
@@ -41,6 +41,8 @@
41
41
  "type": "module",
42
42
  "scripts": {
43
43
  "typecheck": "tsc --noEmit",
44
+ "lint": "biome lint src examples",
45
+ "format": "biome format --write src examples",
44
46
  "test": "bun test test/",
45
47
  "update-models": "bun src/update-models.ts",
46
48
  "fetch-latest-provider-docs": "bun references/documentations/fetch-latest.ts"
@@ -49,6 +51,7 @@
49
51
  "zod": "^4.4.3"
50
52
  },
51
53
  "devDependencies": {
54
+ "@biomejs/biome": "2.6.6",
52
55
  "@types/bun": "latest",
53
56
  "typescript": "^7.0.0",
54
57
  "zod": "^4.4.3"