agent-lattice 0.9.14 → 0.9.16

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/README.md CHANGED
@@ -56,6 +56,44 @@ Pass `{ stream: false }` to disable model streaming for a query:
56
56
  const result = await agent.prompt("Say hello", { stream: false });
57
57
  ```
58
58
 
59
+ Pass `outputFormat` when you want the model to produce JSON matching a schema:
60
+
61
+ ```ts
62
+ const jsonResult = await agent.prompt("Return JSON only.", {
63
+ outputFormat: "json",
64
+ });
65
+
66
+ const result = await agent.prompt("Return the answer to 2 + 2.", {
67
+ outputFormat: {
68
+ type: "json_schema",
69
+ schema: {
70
+ type: "object",
71
+ properties: {
72
+ answer: { type: "number" },
73
+ },
74
+ required: ["answer"],
75
+ additionalProperties: false,
76
+ },
77
+ },
78
+ });
79
+ ```
80
+
81
+ When `outputFormat` is set, the SDK verifies that the final answer is a pure
82
+ JSON value. If a compatible provider ignores structured output parameters and
83
+ returns Markdown or prose, the run finishes with an error result.
84
+
85
+ For GLM/ZAI-compatible providers, use `structuredOutputMode: "json_object"` if
86
+ your `baseURL` is a custom proxy that auto-detection cannot recognize:
87
+
88
+ ```ts
89
+ const agent = createAgent({
90
+ apiKey: process.env.ZAI_API_KEY,
91
+ baseURL: "https://api.bigmodel.cn/anthropic",
92
+ model: "glm-5.2",
93
+ structuredOutputMode: "json_object",
94
+ });
95
+ ```
96
+
59
97
  ## Multimodal Input
60
98
 
61
99
  Pass Anthropic-compatible content blocks for image or document prompts:
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { DocumentBlockParam, ImageBlockParam, TextBlockParam } from "@anthropic-ai/sdk/resources/messages.mjs";
2
+ import type { BetaJSONOutputFormat } from "@anthropic-ai/sdk/resources/beta/messages/messages.mjs";
2
3
  import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
3
4
  import { type StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
4
5
  import { type StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
@@ -149,6 +150,7 @@ export type ModelRequest = {
149
150
  messages: ModelMessage[];
150
151
  tools: ModelToolDefinition[];
151
152
  stream: boolean;
153
+ outputFormat?: OutputFormat;
152
154
  onStreamEvent?: (event: Record<string, unknown>) => void;
153
155
  signal?: AbortSignal;
154
156
  };
@@ -355,6 +357,7 @@ export type AgentWorkspaceOptions = string | {
355
357
  export type AgentOptions<TContext = unknown> = {
356
358
  apiKey?: string;
357
359
  baseURL?: string;
360
+ structuredOutputMode?: StructuredOutputMode;
358
361
  name?: string;
359
362
  model: string;
360
363
  systemPrompt?: string;
@@ -375,12 +378,15 @@ export type AgentWorkspaceToolsOptions = {
375
378
  };
376
379
  export type QueryOptions<TContext = unknown> = {
377
380
  stream?: boolean;
381
+ outputFormat?: OutputFormat;
378
382
  signal?: AbortSignal;
379
383
  context?: TContext;
380
384
  agentRuntime?: AgentRuntimeContext;
381
385
  permissions?: RuntimePermissions;
382
386
  tracer?: ContextTracer;
383
387
  };
388
+ export type OutputFormat = "json" | BetaJSONOutputFormat;
389
+ export type StructuredOutputMode = "auto" | "anthropic" | "json_object";
384
390
  export type SDKSystemInitMessage = {
385
391
  type: "system";
386
392
  subtype: "init";
@@ -453,6 +459,8 @@ export declare class MaxTurnsError extends AgentSDKError {
453
459
  }
454
460
  export declare class AbortError extends AgentSDKError {
455
461
  }
462
+ export declare class StructuredOutputError extends AgentSDKError {
463
+ }
456
464
  export declare class ToolPermissionDeniedError extends AgentSDKError {
457
465
  readonly denial: PermissionDenial;
458
466
  constructor(denial: PermissionDenial);
@@ -512,6 +520,7 @@ export declare function createAgentWorkspaceTools(options?: AgentWorkspaceToolsO
512
520
  export declare function query<TContext = unknown>(params: AgentOptions<TContext> & {
513
521
  prompt: string;
514
522
  stream?: boolean;
523
+ outputFormat?: OutputFormat;
515
524
  signal?: AbortSignal;
516
525
  context?: TContext;
517
526
  }): AsyncGenerator<SDKMessage>;