Skip to content

feat(cmdcode): tool calling support - #9

Merged
evangit2 merged 1 commit into
mainfrom
develop
Jul 31, 2026
Merged

feat(cmdcode): tool calling support#9
evangit2 merged 1 commit into
mainfrom
develop

Conversation

@evangit2

Copy link
Copy Markdown
Owner

Summary

Add full tool calling support to the Command Code provider client.

Changes

Tool passing

  • _build_generate_body now forwards the tools array from the OpenAI request to the Command Code API
  • Converts OpenAI tool format (parameters) to CC format (input_schema)
  • Handles tool role messages (tool results) in the message conversion

Structured tool call event handling (primary)

The Command Code API returns structured SSE events for tool calls when tools are passed correctly:

  • tool-input-start → creates tool call placeholder with ID and name
  • tool-input-delta → accumulates argument JSON fragments
  • tool-input-end → finalizes arguments
  • tool-call → complete tool call (id, name, input)

These are handled in both streaming and non-streaming paths and translated to OpenAI-compatible tool_calls objects.

DSML parser (fallback)

Added a DSML <|DSML|tool_calls> parser as a fallback for cases where a model emits tool calls as text rather than structured events. Supports:

  • <|DSML|invoke name="..."> with <|DSML|parameter> tags
  • <name>/<parameters> JSON format
  • ASCII pipe variant <|DSML|...>
  • Multiple invokes in one block
  • Partial marker detection across streaming deltas

Response builders

  • _make_openai_chunk now accepts tool_calls parameter for streaming
  • _make_openai_response now accepts tool_calls parameter for non-streaming
  • finish_reason set to "tool_calls" when tool calls are emitted

Testing

  • ✅ Streaming tool call (calculator: 2+2{"expression": "2+2"})
  • ✅ Non-streaming tool call
  • ✅ Tool result round-trip (tool result → model responds with content)
  • ✅ No-tools backward compatibility
  • ✅ All 27 existing tests pass
  • ✅ DSML parser unit tests (7 test cases)

…SML fallback

- Pass tools from OpenAI request to Command Code API using input_schema format
- Handle tool-input-start/delta/end and tool-call SSE events in both paths
- Convert OpenAI tool definitions (parameters → input_schema) for CC API
- Handle tool role messages (tool results) in _build_generate_body
- Add DSML <|DSML|tool_calls> parser as fallback for models that emit text
- Add _make_openai_chunk/_make_openai_response tool_calls support
- Tested: streaming + non-streaming tool calls, tool result round-trip, no-tools backward compat
- All 27 existing tests pass
@evangit2
evangit2 merged commit 07231b2 into main Jul 31, 2026
2 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.

1 participant