Skip to content

feat(core): E4.5 real provider tool-calling - #28

Merged
ajianaz merged 4 commits into
developfrom
feat/e45-real-tool-calling
Aug 27, 2026
Merged

ajianaz merged 4 commits into
developfrom
feat/e45-real-tool-calling

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What

  • Tool::spec() method: each tool supplies its own JSON Schema parameters (cora_search, uteke_search, read_file, gh)
  • ToolRegistry::specs(): serializes all specs into the OpenAI tools array, sorted by name for deterministic payloads
  • OpenAiProvider::with_tool_specs(): stores tool definitions sent with every /chat/completions request
  • ChatRequest.tools + ChatMessage tool_calls/tool_call_id: full wire format support
  • Response parsing: choices[].message.tool_calls → ProviderOutput::ToolCall (previously silently dropped)
  • Transcript flatten: Intent entries → assistant messages with tool_calls; ToolResult entries → tool-role messages with tool_call_id (previously filtered out — the model never saw tool output)
  • CLI run/resume pass registry.specs() to the provider

Why

Tole's turn loop, state machine, and tool registry were complete, but the OpenAI wire layer never sent tool definitions and never returned tool results to the model. Live smoke test confirmed the model could not call any tool. E4.5 closes this gap — the agent loop now works end-to-end against a real provider.

Testing

  • cargo test --workspace: 100/100 pass (4 new tests: spec serialization, tool_calls parsing, intent flatten, tool_result flatten)
  • cargo clippy --workspace --all-targets: 0 warnings
  • cora review --diff-file: clean (0 issues)
  • Live smoke test (Bifrost/GLM): prompt requiring cora_search → durable log shows intent_4 (tool: cora_search, {"query":"loop guard fingerprint"}) → tool_result ok → model replies DONE. Full tool-calling loop verified against real provider.

Closes #27

- Tool::spec() supplies JSON Schema parameters per tool; registry
  serializes specs() into the OpenAI tools array (sorted, deterministic)
- OpenAiProvider: with_tool_specs(), ChatRequest.tools, ChatMessage
  tool_calls/tool_call_id, response parsing emits ProviderOutput::ToolCall
- flatten transcript: Intent entries become assistant tool_calls messages,
  ToolResult entries become tool-role messages with tool_call_id
- specs for cora_search, uteke_search, read_file, gh (validated live:
  model now sends correct arguments)
- CLI wires registry.specs() into provider for run and resume

Closes #27
Comment thread crates/tole-core/src/openai.rs Fixed
Comment thread crates/tole-core/src/openai.rs Fixed
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

- tool_result/error content now passes through scrub() before the wire,
  extending E11 redaction to tool outputs that may echo the API key
- malformed tool_calls arguments are surfaced to the model as a
  parse-error result instead of silently running with {}
Comment thread crates/tole-core/src/openai.rs Fixed
- new ProviderOutput::InvalidToolArgs variant: parse failures in
  tool_calls.arguments no longer produce a synthetic ToolCall input
- turn loop records the intent and settles it as an error sandwich
  WITHOUT executing the tool — the model sees the parse error and
  can retry with well-formed JSON
e.payload
.get("output")
.cloned()
.unwrap_or_else(|| json!({ "ok": true }))
Turn-level errors (budget exhausted, invalid tool arguments) have no
parent intent; emitting them as tool messages with a null tool_call_id
makes the OpenAI API reject the next request with 400.
@ajianaz
ajianaz merged commit 3c1f8c9 into develop Aug 27, 2026
11 checks passed
@ajianaz
ajianaz deleted the feat/e45-real-tool-calling branch August 27, 2026 04: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.

E4.5: wire real tool-calling through OpenAI provider

2 participants