agent-lattice 0.22.0 → 0.24.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/README.md CHANGED
@@ -227,8 +227,10 @@ await agent.prompt("Remember that my name is Ada.");
227
227
  Each JSONL entry includes `session_id`, `run_id`, `seq`, `source`, `type`, and
228
228
  `data`. Agent runs record transcript and context events such as `run_start`,
229
229
  `user_message`, `model_request`, `assistant_message`, `tool_use`,
230
- `tool_result`, and `result`. For team runners, pass the tracer per query to
231
- propagate it into delegated agents:
230
+ `tool_result`, and `result`. When the model client reports token usage,
231
+ `assistant_message` events carry it as `data.message.usage`, and the `result`
232
+ event carries the query's summed usage as `data.usage` (since 0.23.1). For
233
+ team runners, pass the tracer per query to propagate it into delegated agents:
232
234
 
233
235
  ```ts
234
236
  for await (const event of team.query("Ask engineering to investigate.", {
@@ -316,6 +318,13 @@ root and share one trace session. Each Agent keeps its own SDK session identity,
316
318
  recorded as `agent_session_id` metadata, so tracing does not change Agent state
317
319
  or returned SDK messages.
318
320
 
321
+ When the model client reports token usage, each `llm` run ends with
322
+ `usage_metadata` in its outputs (`input_tokens`, `output_tokens`,
323
+ `total_tokens`, plus cache buckets under `input_token_details`), so LangSmith
324
+ shows token consumption and inferred cost per model turn. Anthropic cache
325
+ tokens are additive, so they are summed into `input_tokens` the same way
326
+ LangSmith's own Anthropic wrapper does. *Requires 0.23.1 or later.*
327
+
319
328
  ## Langfuse Context Tracing
320
329
 
321
330
  *Requires 0.19.0 or later.*
@@ -389,6 +398,13 @@ as child `generation` observations and SDK tool calls as child `tool`
389
398
  observations. For a `Team` query, delegated runs nest as child `chain`
390
399
  observations under the team root, so one handoff invocation stays one trace.
391
400
 
401
+ When the model client reports token usage, each `generation` observation ends
402
+ with `usageDetails` (`input`, `output`, `cache_creation_input_tokens`,
403
+ `cache_read_input_tokens`, `total`), so Langfuse shows token consumption and
404
+ inferred cost per model turn. Anthropic `input_tokens` already excludes cache
405
+ tokens, matching Langfuse's mutually-exclusive usage buckets. *Requires 0.23.1
406
+ or later.*
407
+
392
408
  `startObservation` defaults to the bundled `@langfuse/tracing` function; pass
393
409
  `startObservation` only to inject a custom runtime or a test fake.
394
410
 
@@ -578,6 +594,26 @@ explicit `outputSchema` still applies. Whenever a schema is in effect, the
578
594
  generated tool description states that the tool returns the target's
579
595
  validated structured output as JSON.
580
596
 
597
+ Two more contract combinations are pinned down since 0.23.0:
598
+
599
+ - **Target declares no `outputSchema`, `agentTool()` declares one
600
+ explicitly.** Assembly allows it (nothing to cross-check against), and an
601
+ `ask` call validates the child's `structuredResult` against the parent-side
602
+ schema and returns it as JSON. This fits children that end through a custom
603
+ `endTurn` + `structuredResult` tool performing domain validation beyond the
604
+ schema (for example reference truthfulness), with the contract declared by
605
+ the parent alone.
606
+ - **Neither side declares a schema.** When the child ends with a
607
+ `structuredResult`, the `ask` tool result is its JSON as-is (unvalidated)
608
+ instead of falling back to the text content and dropping it. The trust
609
+ level is the same as the text result; the schema's job is validation only,
610
+ not gating the structured channel. This applies on both the direct path and
611
+ the team runtime delegate path.
612
+
613
+ *Behavior change in 0.23.0:* existing code where the child ends with
614
+ `endTurn` + `structuredResult` and the parent declares no schema now receives
615
+ the structured JSON from `ask` instead of the text content.
616
+
581
617
  ### Typed delegation
582
618
 
583
619
  *Requires 0.21.0 or later.*
@@ -648,6 +684,14 @@ an `isConcurrencySafe` declaration stay sequential. Use `mode: "all"` only when
648
684
  every tool in the Agent is safe to overlap. Use `mode: "sequential"` to disable
649
685
  tool concurrency even for tools marked safe.
650
686
 
687
+ `agentTool()` accepts the same declaration as `AgentToolOptions.isConcurrencySafe`,
688
+ so a supervisor can fan out independent delegations in one turn. The input the
689
+ predicate receives is the tool's parsed input — the `inputSchema`-validated
690
+ value for typed delegation, the `AgentToolInput` shape otherwise. Keep in mind
691
+ the target's lifecycle: an `AgentSpec` spawns a fresh session per call, while an
692
+ `AgentLike` target keeps history across calls and is usually not safe to call
693
+ concurrently. *Requires 0.24.0 or later.*
694
+
651
695
  When concurrency is available, the SDK tells the model to batch independent
652
696
  calls and to use separate assistant responses when a later call needs an earlier
653
697
  result. Runtime safety checks and `toolBatchPolicy` remain authoritative.
@@ -1390,6 +1434,14 @@ production hosts should pair write and shell access with a permission callback.
1390
1434
  Shell redirects to `/dev/null` are treated as discard targets, not workspace
1391
1435
  writes.
1392
1436
 
1437
+ Pass `workspace: false` to opt out of the built-in workspace entirely — no
1438
+ built-in file/shell tools and no workspace prompt section, equivalent to
1439
+ `createBareAgent()` (*requires 0.23.0 or later*). Unlike `createBareAgent()`,
1440
+ the option also works through `defineAgent()`, so
1441
+ `defineAgent({ workspace: false })` spawns bare sessions — handy for
1442
+ typed-delegation specialists that should have no filesystem or shell surface
1443
+ at all.
1444
+
1393
1445
  ## Multi-turn Session
1394
1446
 
1395
1447
  ```ts
package/dist/index.d.ts CHANGED
@@ -612,7 +612,13 @@ export type AgentOptions<TContext = unknown> = {
612
612
  autoCompact?: boolean | AutoCompactOptions;
613
613
  toolConcurrency?: ToolConcurrencyOptions;
614
614
  skills?: SkillDefinition[];
615
- workspace?: AgentWorkspaceOptions;
615
+ /**
616
+ * Workspace root for the built-in file/shell tools. `false` disables the
617
+ * built-in workspace entirely: no workspace tools, no workspace prompt
618
+ * section — equivalent to `createBareAgent`, and the way to make
619
+ * `defineAgent` spawn bare sessions.
620
+ */
621
+ workspace?: AgentWorkspaceOptions | false;
616
622
  permission?: (request: PermissionRequest) => Promise<PermissionDecision> | PermissionDecision;
617
623
  modelClient?: ModelClient;
618
624
  tracer?: ContextTracer;
@@ -845,7 +851,10 @@ export type AgentToolOptions = {
845
851
  * With the schema in effect, the tool result is the target's validated
846
852
  * structured output as JSON; a target that ends without submitting — or
847
853
  * submits a payload that fails the schema — produces a `child_output_invalid`
848
- * tool error the parent can retry.
854
+ * tool error the parent can retry. Without any schema, a `structuredResult`
855
+ * the target produced is still passed through as JSON (same trust level as
856
+ * the text result); schema only adds validation, it does not gate the
857
+ * structured channel.
849
858
  */
850
859
  outputSchema?: OutputSchema;
851
860
  /**
@@ -863,6 +872,17 @@ export type AgentToolOptions = {
863
872
  * runtime the projected prompt must be a string.
864
873
  */
865
874
  mapInput?: (input: any) => string | ContentBlock[];
875
+ /**
876
+ * Same contract as `ToolOptions.isConcurrencySafe`: under
877
+ * `toolConcurrency.mode: "safe"` (the default), only calls whose declaration
878
+ * returns true here run in parallel; omitted means sequential. For typed
879
+ * delegation the input is the `inputSchema`-validated value (the same value
880
+ * `mapInput` receives); for default delegation it is the `AgentToolInput`
881
+ * shape. Note the target matters: an AgentSpec spawns a fresh session per
882
+ * call, while an AgentLike target keeps history across calls and is usually
883
+ * not safe to call concurrently.
884
+ */
885
+ isConcurrencySafe?: (input: any) => boolean;
866
886
  };
867
887
  /**
868
888
  * An AgentLike is a live session: it keeps its conversation history across