From 6809dca431d28088a8e5aad3ba7fae3dc85be7a4 Mon Sep 17 00:00:00 2001 From: aship1619-byte Date: Wed, 29 Jul 2026 17:20:40 +0530 Subject: [PATCH 1/5] updated example --- README.md | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 21fe4a0..16acee3 100644 --- a/README.md +++ b/README.md @@ -175,16 +175,13 @@ curl -fsSL https://cli.swytchcode.com/install.sh | sh # 2. Scaffold .swytchcode/ + tooling.json in your project swytchcode init -# 3. Log in (opens a browser; creates your Swytchcode session) -swytchcode login - -# 4. Fetch the GitHub integration +# 3. Fetch the GitHub integration swytchcode get github -# 5. Enable the "star a repo" tool - the trust boundary for what this project can call -swytchcode add github.user.starred.update +# 4. Enable the "star a repo" tool - the trust boundary for what this project can call +swytchcode add method github.user.starred.update -# 6. Connect your GitHub account (opens a browser for the OAuth flow) +# 5. Connect your GitHub account (opens a browser for the OAuth flow) swytchcode auth connect github ``` @@ -222,17 +219,42 @@ async function runAgent() { // just describing what it would do const system = `You are a helpful assistant.\n\n${TOOL_USE_INSTRUCTIONS}`; + const messages: Anthropic.MessageParam[] = [ + { role: "user", content: "Star the swytchcodehq/swytchcode-examples repo on GitHub for me." }, + ]; + const response = await anthropic.messages.create({ model: "claude-opus-5", max_tokens: 1024, system, tools: tools, - messages: [{ role: "user", content: "Star the swytchcodehq/swytchcode-examples repo on GitHub for me." }], + messages, }); - // 4. Run any tool calls Claude made and send the results back - const results = await swx.handleToolCalls(response); - console.log(results); + // 4. Run any tool calls Claude made, then send the results back so Claude + // can turn them into a final natural-language reply instead of a raw tool_result block + const toolResults = await swx.handleToolCalls(response); + + if (toolResults.length > 0) { + messages.push({ role: "assistant", content: response.content }); + messages.push({ role: "user", content: toolResults as Anthropic.ToolResultBlockParam[] }); + + const followUp = await anthropic.messages.create({ + model: "claude-opus-5", + max_tokens: 1024, + system, + tools: tools, + messages, + }); + + for (const block of followUp.content) { + if (block.type === "text") console.log(block.text); + } + } else { + for (const block of response.content) { + if (block.type === "text") console.log(block.text); + } + } } runAgent(); From 5e4b9911bff0be1f5a8d44adb27d5310e22c33b0 Mon Sep 17 00:00:00 2001 From: aship1619-byte Date: Wed, 29 Jul 2026 19:50:49 +0530 Subject: [PATCH 2/5] Continue handling tool calls until Claude stops requesting them. --- README.md | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index f62372d..ed0b99b 100644 --- a/README.md +++ b/README.md @@ -223,37 +223,28 @@ async function runAgent() { { role: "user", content: "Star the swytchcodehq/swytchcode-examples repo on GitHub for me." }, ]; - const response = await anthropic.messages.create({ - model: "claude-sonnet-5", - max_tokens: 1024, - system, - tools: tools, - messages, - }); - - // 4. Run any tool calls Claude made, then send the results back so Claude - // can turn them into a final natural-language reply instead of a raw tool_result block - const toolResults = await swx.handleToolCalls(response); - - if (toolResults.length > 0) { - messages.push({ role: "assistant", content: response.content }); - messages.push({ role: "user", content: toolResults as Anthropic.ToolResultBlockParam[] }); - - const followUp = await anthropic.messages.create({ - model: "claude-opus-5", + // 4. Loop until Claude stops requesting tool calls: run any tool calls + // Claude made and send the results back so it can keep working toward + // a final natural-language reply instead of stopping after one round + let response: Anthropic.Message; + while (true) { + response = await anthropic.messages.create({ + model: "claude-sonnet-5", max_tokens: 1024, system, tools: tools, messages, }); + messages.push({ role: "assistant", content: response.content }); + + if (response.stop_reason !== "tool_use") break; + + const toolResults = await swx.handleToolCalls(response); + messages.push({ role: "user", content: toolResults as Anthropic.ToolResultBlockParam[] }); + } - for (const block of followUp.content) { - if (block.type === "text") console.log(block.text); - } - } else { - for (const block of response.content) { - if (block.type === "text") console.log(block.text); - } + for (const block of response.content) { + if (block.type === "text") console.log(block.text); } } From 7164fa16bb169c566f00cba1840bcfd9f175d690 Mon Sep 17 00:00:00 2001 From: aship1619-byte Date: Wed, 29 Jul 2026 19:58:18 +0530 Subject: [PATCH 3/5] Continue handling tool calls until Claude stops requesting them. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ed0b99b..c173211 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,9 @@ async function runAgent() { }); messages.push({ role: "assistant", content: response.content }); + if (response.stop_reason === "max_tokens") { + throw new Error("Response truncated at max_tokens - increase the limit and retry"); + } if (response.stop_reason !== "tool_use") break; const toolResults = await swx.handleToolCalls(response); From 88161019b4f6e170c11e043ceba3f9e8397fe338 Mon Sep 17 00:00:00 2001 From: aship1619-byte Date: Wed, 29 Jul 2026 20:01:52 +0530 Subject: [PATCH 4/5] added max turns --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c173211..2c32e57 100644 --- a/README.md +++ b/README.md @@ -226,8 +226,13 @@ async function runAgent() { // 4. Loop until Claude stops requesting tool calls: run any tool calls // Claude made and send the results back so it can keep working toward // a final natural-language reply instead of stopping after one round + const MAX_TURNS = 10; let response: Anthropic.Message; - while (true) { + for (let turn = 0; ; turn++) { + if (turn >= MAX_TURNS) { + throw new Error(`Exceeded ${MAX_TURNS} tool-use turns without a final reply`); + } + response = await anthropic.messages.create({ model: "claude-sonnet-5", max_tokens: 1024, From 6b852a1b9c7f38dbd232ec6bf430ad0cd3e18c1d Mon Sep 17 00:00:00 2001 From: aship1619-byte Date: Wed, 29 Jul 2026 20:02:39 +0530 Subject: [PATCH 5/5] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4671fff..4763c7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@swytchcode/runtime", - "version": "1.1.2", + "version": "1.1.3", "description": "Thin runtime wrapper around the Swytchcode CLI", "main": "dist/index.js", "types": "dist/index.d.ts",