Skip to content

feat(core-ai): tool calling for both provider protocols - #4630

Merged
datlechin merged 2 commits into
mainfrom
feat/core-ai-tool-calling
Nov 27, 2026
Merged

datlechin merged 2 commits into
mainfrom
feat/core-ai-tool-calling

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • tablepro-ai now carries tool calls for both provider protocols. The text-only chat path is unchanged.
  • ChatMessage content is Vec<ContentBlock> (Text, ToolUse, ToolResult). ChatMessage::user/assistant still build a single Text block; ChatMessage::text() joins the Text blocks.
  • ChatRequest gains tools: Vec<ToolSpec> (name, description, JSON Schema input).
  • ReplyEvent::ToolCall { id, name, input } and StopReason::ToolUse.
  • Anthropic: serialize tools and tool_use/tool_result blocks (a plain text turn stays a bare string); assemble content_block_start + input_json_delta + content_block_stop into one ToolCall; map stop_reason: tool_use.
  • OpenAI: serialize tools as {type:function, function:{name,description,parameters}} and messages with tool_calls / role:tool results (arguments as a JSON string); assemble streamed delta.tool_calls by index; map finish_reason: tool_calls.
  • FFI and Linux keep compiling and behaving: both drop ToolCall for now and treat ToolUse as a normal end. The FFI UniFFI surface is unchanged, so no bindings were regenerated.

Test plan

  • New tablepro-ai unit tests: Anthropic and OpenAI request serialization carries tools and structured content; streaming parsers assemble a tool_use/tool_calls block from captured SSE chunk sequences into one ReplyEvent::ToolCall with the right id/name/parsed input; stop_reason/finish_reason map to StopReason::ToolUse.
  • macOS: cargo test --locked -p tablepro-ai (59 lib + 14 provider tests green), cargo clippy --locked -p tablepro-ai --all-targets warning-free, cargo check --locked -p tablepro-ffi green, cargo test --locked -p tablepro-ffi --test ai green (text chat unchanged).
  • Linux app full build is Linux-only here (a third-party glycin crate needs memfd); the Linux edits are a struct-field init and two match arms, left for Linux CI.

Fixes #

Spine for agent mode. Text-only chat path is unchanged.

- ChatMessage content is now Vec<ContentBlock> (Text, ToolUse, ToolResult); user()/assistant() still build one Text block, text() joins Text blocks.
- ChatRequest gains tools: Vec<ToolSpec>.
- ReplyEvent::ToolCall and StopReason::ToolUse.
- Anthropic: serialize tools and tool_use/tool_result blocks; assemble streamed tool_use blocks into one ToolCall; map stop_reason tool_use.
- OpenAI: serialize tools as function specs and tool_calls/role:tool messages; assemble streamed delta.tool_calls by index; map finish_reason tool_calls.
- FFI and Linux keep compiling; both drop ToolCall and treat ToolUse as a normal end for now. FFI UniFFI surface unchanged.
@datlechin
datlechin enabled auto-merge (squash) November 27, 2026 09:01
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