Skip to content

feat: wire up tool calling execution in streaming responses#34

Merged
anurag629 merged 3 commits intocodercops:devfrom
Ashok161:feat/issue-16-streaming-tool-calls
Mar 23, 2026
Merged

feat: wire up tool calling execution in streaming responses#34
anurag629 merged 3 commits intocodercops:devfrom
Ashok161:feat/issue-16-streaming-tool-calls

Conversation

@Ashok161
Copy link
Copy Markdown
Contributor

Implements #16 by wiring up the full tool-calling loop for streaming and sync chat responses across all supported providers. Tool calls are now detected, executed server-side, fed back into the provider in the
provider-specific format, and the final assistant response continues streaming to the widget.

What’s included

  • Provider tool-call execution loop for Claude, OpenAI, and Gemini
  • Shared tool execution/error serialization helpers
  • Max tool-iteration guard to prevent infinite loops
  • Server-side tool lookup and execution via configured tools
  • Lead capture webhook dispatch now includes conversationId
  • SSE metadata for successful lead capture: leadCaptured and leadData
  • Widget support for leadCaptured callback/event
  • Added changeset for published package updates

Files changed

  • packages/core/src/providers/openai.ts
  • packages/core/src/providers/claude.ts
  • packages/core/src/providers/gemini.ts
  • packages/core/src/providers/tool-execution.ts
  • packages/core/src/types.ts
  • packages/core/src/index.ts
  • packages/core/tests/providers/tool-calling.test.ts
  • packages/server/src/handler.ts
  • packages/server/tests/handler.test.ts
  • packages/widget/src/api/types.ts
  • packages/widget/src/widget.ts
  • packages/widget/src/index.ts
  • packages/widget/tests/widget.test.ts
  • .changeset/streaming-tool-calls.md

Behavior changes

  • When a provider emits a tool-use response, ChatCops now executes the matching tool and continues the conversation
  • Successful capture_lead tool execution now:
    • tracks analytics
    • dispatches lead:captured webhook with { lead, conversationId }
    • emits SSE metadata to the widget
  • Widget consumers can now handle lead capture through:
    • onLeadCaptured
    • leadCaptured event

Verification

  • corepack pnpm test
  • corepack pnpm -r typecheck

Both passed locally.

Closes

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 22, 2026

@Ashok161 is attempting to deploy a commit to the CODERCOPS Team on Vercel.

A member of the Team first needs to authorize it.

@Ashok161
Copy link
Copy Markdown
Contributor Author

@anurag629 I chose to keep tool execution inside the provider loop via toolExecutor rather than changing AIProvider.chat() to a ChatYield union. This keeps streaming text behavior unchanged for callers , while still supporting provider-specific tool result reinjection. Happy to refactor to a yielded-event interface if you want the abstraction made explicit.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chatcops-website Ready Ready Preview, Comment Mar 22, 2026 5:05pm

Request Review

Copy link
Copy Markdown
Member

@anurag629 anurag629 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the biggest gap in the project — tool calling was completely broken, meaning lead capture (a headline feature) never actually worked. Good implementation across all 3 providers with solid test coverage.

A couple of minor things I noticed but nothing that should block this:

  • The module-level toolCallSequence counters in gemini.ts/openai.ts will grow forever in a long-running server. Fine in practice but worth cleaning up later.
  • No timeout on tool.execute() — if a tool hangs, the stream blocks. I'll open a follow-up issue for this.

Nice work @Ashok161.

@anurag629 anurag629 merged commit 96ff009 into codercops:dev Mar 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wire up tool calling execution in streaming responses

2 participants