Skip to content

Commit d0a3827

Browse files
committed
docs(ai-agents): fix tool wiring and recursive return type in the guides
Pass tools into chat.toStreamTextOptions({ tools }) in the chat agent guide so HITL approval detection and auto-injected skill tools survive, instead of passing them straight to streamText where the merged set is dropped. Give the recursive translate-and-refine task an explicit return type so the copied snippet doesn't hit TypeScript's circular-inference error.
1 parent 488683b commit d0a3827

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

docs/guides/ai-agents/chat-agent.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ export const myChat = chat.agent({
6363
tools: { getCurrentTime },
6464
run: async ({ messages, tools, signal }) => {
6565
return streamText({
66-
...chat.toStreamTextOptions(),
66+
// Pass tools INTO toStreamTextOptions (not separately to streamText):
67+
// this is what detects tool calls needing HITL approval and merges any
68+
// auto-injected skill tools. It sets streamText's `tools` for you.
69+
...chat.toStreamTextOptions({ tools }),
6770
model: anthropic("claude-sonnet-4-5"),
6871
messages,
69-
tools,
7072
stopWhen: stepCountIs(15),
7173
abortSignal: signal,
7274
});

docs/guides/ai-agents/translate-and-refine.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ interface TranslationPayload {
3535
rejectionCount?: number;
3636
}
3737

38+
interface TranslationResult {
39+
finalTranslation: string | undefined;
40+
iterations: number;
41+
status: "MAX_ITERATIONS_REACHED" | "APPROVED";
42+
}
43+
3844
export const translateAndRefine = task({
3945
id: "translate-and-refine",
40-
run: async (payload: TranslationPayload) => {
46+
// Explicit return type: the task returns its own recursive result, so
47+
// annotate it to avoid TypeScript's circular-inference error.
48+
run: async (payload: TranslationPayload): Promise<TranslationResult> => {
4149
const rejectionCount = payload.rejectionCount || 0;
4250

4351
// Bail out if we've hit the maximum attempts

0 commit comments

Comments
 (0)