@trayai/helix-sdk 1.8.0 → 1.13.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/CHANGELOG.md CHANGED
@@ -8,6 +8,29 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
  The SDK and [`@trayai/helix-cli`](https://www.npmjs.com/package/@trayai/helix-cli) are
9
9
  released together and share a version — install matching versions.
10
10
 
11
+ ## 1.9.0
12
+
13
+ ### Added
14
+
15
+ - **Agents and tools are now a documented, public part of the SDK.** Define a tool with
16
+ `defineTool` (`functions/_tools/`) and an agent with `defineAgent` (`functions/_agents/`),
17
+ then run it from any handler with `ctx.agent(name).generate()` / `.stream()`. An agent's
18
+ `model`/`auth` use the same `aiProviders` aliases as `ctx.ai` (every provider, including
19
+ Amazon Bedrock), can declare `fallbacks`, and can delegate to other agents. Conversations
20
+ persist as **sessions** (the full record, not just the model window) — read them with
21
+ `session(id).messages()` / `.page()` and clear them with `session(id).clear()`; cap the model
22
+ window with `memory.maxSessionMessages`, scope sessions per user with `memory.scope: 'user'`.
23
+ Choose a session store with the new `agentSessions` field in `helix.config.ts`
24
+ (`{ store: 'managed' }` by default, or a bring-your-own `{ store: 'dynamodb', … }`). See the
25
+ README's "Agents and tools" section; try them locally with `helix agent list` / `helix agent
26
+ chat`. (These APIs shipped earlier marked beta; the beta label has been removed.)
27
+
28
+ ### Changed
29
+
30
+ - Removed the `@beta` labels from `defineAgent`, `defineTool`, `ctx.agent`, `HelixAgent`, and
31
+ `AgentClient` — the agent harness is now covered by the SDK's semantic-versioning contract
32
+ like the rest of the public API.
33
+
11
34
  ## 1.8.0
12
35
 
13
36
  ### Added
package/README.md CHANGED
@@ -15,6 +15,7 @@ The runtime SDK for **Helix** — a TypeScript-first platform for building integ
15
15
  - [Scheduled functions](#scheduled-functions)
16
16
  - [Async function calls](#async-function-calls)
17
17
  - [AI — `ctx.ai`](#ai--ctxai)
18
+ - [Agents and tools — `ctx.agent`](#agents-and-tools--ctxagent)
18
19
  - [Authentication](#authentication)
19
20
  - [Configuration](#configuration)
20
21
  - [Logging](#logging)
@@ -83,6 +84,7 @@ Every HTTP handler receives a `ctx` (`TrayContext`); scheduled handlers receive
83
84
  | `ctx.kv()` | Key-value store |
84
85
  | `ctx.files()` | File storage |
85
86
  | `ctx.ai(alias)` | AI provider access — credentials are injected by the platform, same as `ctx.http.authed` |
87
+ | `ctx.agent(name)` | Run an agent defined with `defineAgent` — `generate`/`stream`, with persisted conversation sessions |
86
88
  | `ctx.log.info/warn/error/debug` | Structured logging |
87
89
  | `ctx.config` | The `config` block from `helix.config.ts` |
88
90
  | `ctx.state` | Per-request scratch space |
@@ -383,6 +385,125 @@ export default defineFunction(async (ctx) => {
383
385
  and passing a model instance built directly against a third-party AI SDK provider (bypassing
384
386
  `ctx.ai`) throws `SdkError.aiForeignModelRejected`.
385
387
 
388
+ ## Agents and tools — `ctx.agent`
389
+
390
+ An **agent** is an AI loop you define once and run from any handler: it calls a model, decides
391
+ when to use the **tools** you gave it, and keeps a conversation **session** across turns. You
392
+ write agents and tools as files; `ctx.agent(name)` runs them.
393
+
394
+ - **Tools** (`defineTool`) live under `functions/_tools/` — a name, description, Zod `input`
395
+ schema, and a handler. A tool is a normal module you can also call in-process; when an agent
396
+ calls it, the same validation and handler run.
397
+ - **Agents** (`defineAgent`) live under `functions/_agents/`, one file per agent. The agent
398
+ declares its `model` and `auth` (an `aiProviders`/`authentications` alias, exactly like
399
+ `ctx.ai`), its `instructions`, and the `tools` it may call.
400
+
401
+ ```typescript
402
+ // functions/_tools/lookup_order.ts
403
+ import { defineTool } from '@trayai/helix-sdk';
404
+ import { z } from 'zod';
405
+
406
+ export default defineTool({
407
+ name: 'lookup_order',
408
+ description: 'Look up an order by its id.',
409
+ input: z.object({ orderId: z.string() }),
410
+ async handler(ctx) {
411
+ const res = await ctx.http.authed('shop').get(`https://api.shop.example/orders/${ctx.input.orderId}`);
412
+ return res.body; // { status, body?, headers } — see Authenticated HTTP
413
+ },
414
+ });
415
+ ```
416
+
417
+ ```typescript
418
+ // functions/_agents/support-agent.ts
419
+ import { defineAgent } from '@trayai/helix-sdk';
420
+ import lookupOrder from '../_tools/lookup_order.js';
421
+
422
+ export default defineAgent({
423
+ name: 'support-agent',
424
+ description: 'Answers customer support questions.',
425
+ model: 'claude-sonnet-4-5',
426
+ auth: 'anthropicKey', // an aiProviders alias, like ctx.ai
427
+ instructions: 'You are a helpful support agent. Use tools to look up real data.',
428
+ tools: [lookupOrder],
429
+ });
430
+ ```
431
+
432
+ Run it from any function:
433
+
434
+ ```typescript
435
+ import { defineFunction } from '@trayai/helix-sdk';
436
+ import { z } from 'zod';
437
+ import '../_agents/support-agent.js'; // register the agent (see note below)
438
+
439
+ export const input = z.object({
440
+ message: z.string(),
441
+ sessionId: z.string().optional(),
442
+ });
443
+
444
+ export default defineFunction<typeof input>(async (ctx) => {
445
+ const result = await ctx.agent('support-agent').generate({
446
+ prompt: ctx.input.message,
447
+ sessionId: ctx.input.sessionId, // omit to start a new conversation
448
+ });
449
+ return { text: result.text, sessionId: result.sessionId };
450
+ });
451
+ ```
452
+
453
+ - **`generate(options)`** runs the loop to completion and resolves with the model result plus
454
+ the `sessionId` it used. **`stream(options)`** returns the AI SDK stream result (with its
455
+ `sessionId`) for token-by-token responses. Both accept a `prompt` (or `messages`) and an
456
+ optional `sessionId`.
457
+ - **Deployed functions must import the agent module** (e.g. `import '../_agents/support-agent.js'`)
458
+ so it registers before `ctx.agent(name)` runs — only `helix dev` auto-loads `_agents/`; an
459
+ unknown name throws `Unknown agent "<name>"`.
460
+ - **`model` / `auth`** reference the same `aiProviders` + `authentications` aliases as
461
+ `ctx.ai`, so every provider works — including **Amazon Bedrock** (`auth` pointing at a
462
+ Bedrock authentication and a Bedrock model id). Declare one or more `fallbacks`
463
+ (`{ model, auth }` pairs) and the agent retries the next on a model error.
464
+ - **Tools** passed to `defineAgent` are given to the model automatically. Set
465
+ `needsApproval: true` (or a predicate of the input) on a tool and the loop pauses for human
466
+ approval before that tool runs.
467
+ - **Delegation** — list other agents' names in `agents: [...]` and the agent can hand work to
468
+ them as sub-agents (each keeps its own session; nesting is capped).
469
+
470
+ ### Sessions
471
+
472
+ A session is the **full record of a conversation**, not just the model's context window —
473
+ appends never delete, and there is no default expiry, so an app can always show a user their
474
+ earlier conversations. `ctx.agent(name).session(sessionId)` reads and manages one:
475
+
476
+ ```typescript
477
+ const agent = ctx.agent('support-agent');
478
+ const history = await agent.session(sessionId).messages(); // whole conversation
479
+ const page = await agent.session(sessionId).page({ limit: 50, order: 'desc' }); // newest first
480
+ await agent.session(sessionId).clear(); // delete the conversation
481
+ ```
482
+
483
+ - **`memory.maxSessionMessages`** (default 200) caps only what the **model** is sent each turn
484
+ — never what is stored. **`memory.ttl`** (seconds) is opt-in idle retention; omit it and
485
+ sessions are kept until you `clear()` them.
486
+ - **`memory.scope: 'user'`** keys sessions by the invoking user (`ctx.identity`), so each user
487
+ only sees their own; `agent.sessions({ first, cursor })` then lists the calling user's recent
488
+ sessions, newest first. The default scope is `'project'` (sessions shared across the
489
+ project's executions). `agent.sessions()` requires the **managed** store (below) and a
490
+ `'user'`-scoped agent — it is not supported on the bring-your-own DynamoDB store.
491
+
492
+ Choose where sessions are stored with the `agentSessions` field in `helix.config.ts`:
493
+
494
+ ```typescript
495
+ export default defineConfig({
496
+ // ...
497
+ // Managed by Helix (the default — nothing to configure):
498
+ agentSessions: { store: 'managed' },
499
+ // …or bring your own DynamoDB table (credentials injected by the platform):
500
+ // agentSessions: { store: 'dynamodb', auth: '<aws-alias>', table: 'agent-sessions', region: 'us-east-1' },
501
+ });
502
+ ```
503
+
504
+ Try agents locally with `helix dev`, then `helix agent list` and `helix agent chat <name>`
505
+ (see the `@trayai/helix-cli` README).
506
+
386
507
  ## Authentication
387
508
 
388
509
  Authenticated features (`ctx.http.authed`, `ctx.kv`, `ctx.files`, `ctx.ai`) require you to be logged in during local development:
@@ -1,5 +1,5 @@
1
1
  import { z, ZodType } from 'zod';
2
- import { P as PlatformContext } from './types-CRUtefiq.js';
2
+ import { P as PlatformContext } from './types-CVW_-1wh.js';
3
3
 
4
4
  interface SdkRuntimeConfig {
5
5
  /**
@@ -652,9 +652,6 @@ declare function requireWorkspaceId(config: LoadedTrayConfig): string;
652
652
  /**
653
653
  * `defineTool` (helix-spec 12) — the subset agents consume (helix-spec 14).
654
654
  *
655
- * **Beta.** Agents and tools are in beta: this API may change in a future
656
- * release without a major version bump.
657
- *
658
655
  * A tool is a *definition*: name, description, input schema, approval policy,
659
656
  * and handler together in one default export. Tools are:
660
657
  *
@@ -714,8 +711,6 @@ interface HelixToolLike {
714
711
  }
715
712
  /**
716
713
  * Define a tool an agent can call (or that your code can invoke in-process).
717
- *
718
- * @beta Agents and tools are in beta and may change in a future release.
719
714
  */
720
715
  declare function defineTool<TSchema extends ZodType>(config: DefineToolConfig<TSchema>): HelixTool<TSchema>;
721
716
  /** Structural check for defineTool output — see TOOL_DEFINITION_KIND. */
@@ -726,9 +721,6 @@ declare function isToolDefinition(value: unknown): value is HelixTool;
726
721
  * `functions/_agents/`, definitions in code, the file system as the source of
727
722
  * truth.
728
723
  *
729
- * **Beta.** Agents and tools are in beta: this API may change in a future
730
- * release without a major version bump.
731
- *
732
724
  * Like `defineSchedule`, the SDK owns the definition + runtime and the
733
725
  * host (dev server, lambda router) owns discovery: importing the module
734
726
  * registers the agent by name.
@@ -897,8 +889,6 @@ interface AgentDefinition extends z.output<typeof agentConfigSchema> {
897
889
  }
898
890
  /**
899
891
  * Define an agent (default export of a file under `functions/_agents/`).
900
- *
901
- * @beta Agents and tools are in beta and may change in a future release.
902
892
  */
903
893
  declare function defineAgent(config: AgentDefinitionConfig): AgentDefinition;
904
894
  /** Structural check for defineAgent output — see AGENT_DEFINITION_KIND. */
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as h3 from 'h3';
2
2
  import { ZodType } from 'zod';
3
- import { F as FunctionHandler, D as DefineFunctionOptions, a as DefineScheduleConfig, S as ScheduleDefinition, P as PlatformContext } from './types-CRUtefiq.js';
4
- export { A as AgentApprovalDecision, b as AgentCallOptions, c as AgentClient, d as AgentPendingApproval, e as AgentResult, f as AgentSession, g as AgentSessionPage, h as AgentSessionPageOptions, i as AgentSessionSummary, j as AgentSessionsList, k as AgentStreamResult, l as AiEmbeddingModelInstance, m as AiImageModelInstance, n as AiLanguageModelInstance, o as AiSpeechModelInstance, p as AiTranscriptionModelInstance, B as BrokerAuthedClient, q as BrokerCallOptions, r as BrokerCallResult, C as CallFunctionAsync, s as DbCallParameters, t as DbClient, u as FileSystemClient, H as HelixAI, v as HelixAIProvider, w as HelixAgent, x as HelixCost, y as HelixResultMeta, z as HttpClient, K as KeyValueStore, L as Logger, E as S3SignOptions, G as S3SignResult, I as ScheduleContext, J as ScheduleHandler, M as ScheduleTrigger, N as SqlBuilder, T as TrayContext, U as UnvalidatedInput } from './types-CRUtefiq.js';
5
- import { T as TrayConfig, L as LoadedTrayConfig, W as WatchErrorPhase } from './define-agent-Cc6mFat1.js';
6
- export { A as AGENT_DEFINITION_KIND, a as AI_SERVICES, b as AgentDefinition, c as AgentDefinitionConfig, d as AgentSessionsConfig, e as AiProviderEntry, f as AiService, C as ConfigFileOptions, D as DefineToolConfig, H as HELIX_CONFIG_ENV, g as HelixTool, h as HelixToolLike, P as ProvisionedTrayConfig, S as SdkRuntimeConfig, i as TOOL_DEFINITION_KIND, U as UnprovisionedTrayConfig, j as WORKSPACE_ID_REQUIRED_CODE, k as WorkspaceIdRequiredError, l as agentSessionsSchema, m as aiProviderEntrySchema, n as defineAgent, o as defineTool, p as getSdkConfig, q as isAgentDefinition, r as isToolDefinition, s as loadConfig, t as loadedTrayConfigSchema, u as projectIdSchema, v as requireWorkspaceId, w as resolveConfigFile, x as resolveConfigOverride, y as workspaceIdSchema } from './define-agent-Cc6mFat1.js';
3
+ import { F as FunctionHandler, D as DefineFunctionOptions, a as DefineScheduleConfig, S as ScheduleDefinition, P as PlatformContext } from './types-CVW_-1wh.js';
4
+ export { A as AgentApprovalDecision, b as AgentCallOptions, c as AgentClient, d as AgentPendingApproval, e as AgentResult, f as AgentSession, g as AgentSessionPage, h as AgentSessionPageOptions, i as AgentSessionSummary, j as AgentSessionsList, k as AgentStreamResult, l as AiEmbeddingModelInstance, m as AiImageModelInstance, n as AiLanguageModelInstance, o as AiSpeechModelInstance, p as AiTranscriptionModelInstance, B as BrokerAuthedClient, q as BrokerCallOptions, r as BrokerCallResult, C as CallFunctionAsync, s as DbCallParameters, t as DbClient, u as FileSystemClient, H as HelixAI, v as HelixAIProvider, w as HelixAgent, x as HelixCost, y as HelixResultMeta, z as HttpClient, K as KeyValueStore, L as Logger, E as S3SignOptions, G as S3SignResult, I as ScheduleContext, J as ScheduleHandler, M as ScheduleTrigger, N as SqlBuilder, T as TrayContext, U as UnvalidatedInput } from './types-CVW_-1wh.js';
5
+ import { T as TrayConfig, L as LoadedTrayConfig, W as WatchErrorPhase } from './define-agent-DXV_nHvs.js';
6
+ export { A as AGENT_DEFINITION_KIND, a as AI_SERVICES, b as AgentDefinition, c as AgentDefinitionConfig, d as AgentSessionsConfig, e as AiProviderEntry, f as AiService, C as ConfigFileOptions, D as DefineToolConfig, H as HELIX_CONFIG_ENV, g as HelixTool, h as HelixToolLike, P as ProvisionedTrayConfig, S as SdkRuntimeConfig, i as TOOL_DEFINITION_KIND, U as UnprovisionedTrayConfig, j as WORKSPACE_ID_REQUIRED_CODE, k as WorkspaceIdRequiredError, l as agentSessionsSchema, m as aiProviderEntrySchema, n as defineAgent, o as defineTool, p as getSdkConfig, q as isAgentDefinition, r as isToolDefinition, s as loadConfig, t as loadedTrayConfigSchema, u as projectIdSchema, v as requireWorkspaceId, w as resolveConfigFile, x as resolveConfigOverride, y as workspaceIdSchema } from './define-agent-DXV_nHvs.js';
7
7
  export { a as REGION_VALUES, R as Region, r as regionSchema } from './region-schema-COfWyGI9.js';
8
8
  import { StopCondition, ToolSet } from 'ai';
9
9
  export { EmbedManyResult, EmbedResult, EmbeddingModel, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextResult, ImageModel, LanguageModel, LanguageModelUsage, ModelMessage, Output, PrepareStepFunction, SpeechModel, SpeechResult, StopCondition, StreamObjectResult, StreamTextResult, TextStreamPart, ToolChoice, ToolSet, TranscriptionModel, TranscriptionResult, UIMessage, convertToModelMessages, cosineSimilarity, dynamicTool, hasToolCall, jsonSchema, smoothStream, stepCountIs, tool, zodSchema } from 'ai';
@@ -1,7 +1,7 @@
1
- import { L as LoadedTrayConfig, b as AgentDefinition } from '../define-agent-Cc6mFat1.js';
2
- export { z as SdkConfigInput, B as setSdkConfig } from '../define-agent-Cc6mFat1.js';
3
- import { j as AgentSessionsList, b as AgentCallOptions, e as AgentResult } from '../types-CRUtefiq.js';
4
- export { O as SessionExpiredError, Q as clearAgentSessions } from '../types-CRUtefiq.js';
1
+ import { L as LoadedTrayConfig, b as AgentDefinition } from '../define-agent-DXV_nHvs.js';
2
+ export { z as SdkConfigInput, B as setSdkConfig } from '../define-agent-DXV_nHvs.js';
3
+ import { j as AgentSessionsList, b as AgentCallOptions, e as AgentResult } from '../types-CVW_-1wh.js';
4
+ export { O as SessionExpiredError, Q as clearAgentSessions } from '../types-CVW_-1wh.js';
5
5
  import 'zod';
6
6
  import 'h3';
7
7
  import 'ky';
@@ -1,4 +1,4 @@
1
- import { P as PlatformContext } from '../types-CRUtefiq.js';
1
+ import { P as PlatformContext } from '../types-CVW_-1wh.js';
2
2
  import 'h3';
3
3
  import 'ky';
4
4
  import 'zod';
@@ -392,8 +392,6 @@ type AgentStreamResult = StreamTextReturn & {
392
392
  };
393
393
  /**
394
394
  * What `ctx.agent(name)` returns.
395
- *
396
- * @beta Agents and tools are in beta and may change in a future release.
397
395
  */
398
396
  interface HelixAgent {
399
397
  /** The AI SDK loop + session handling. */
@@ -422,8 +420,6 @@ interface HelixAgent {
422
420
  }
423
421
  /**
424
422
  * `ctx.agent` — look up a registered agent by name.
425
- *
426
- * @beta Agents and tools are in beta and may change in a future release.
427
423
  */
428
424
  type AgentClient = (name: string) => HelixAgent;
429
425
 
@@ -517,8 +513,6 @@ interface ContextCore {
517
513
  ai: HelixAI;
518
514
  /**
519
515
  * Agent client (helix-spec 14): `ctx.agent(name).generate()/.stream()`.
520
- *
521
- * @beta Agents and tools are in beta and may change in a future release.
522
516
  */
523
517
  agent: AgentClient;
524
518
  log: Logger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayai/helix-sdk",
3
- "version": "1.8.0",
3
+ "version": "1.13.0",
4
4
  "description": "Helix SDK runtime — defineFunction, ctx, defineConfig, authed HTTP",
5
5
  "license": "Apache-2.0",
6
6
  "author": "trayio",