Skip to content

feat: unified tools= parameter for tool calling#199

Open
Kamilbenkirane wants to merge 14 commits intomainfrom
feat/unified-tools-parameter
Open

feat: unified tools= parameter for tool calling#199
Kamilbenkirane wants to merge 14 commits intomainfrom
feat/unified-tools-parameter

Conversation

@Kamilbenkirane
Copy link
Member

@Kamilbenkirane Kamilbenkirane commented Feb 26, 2026

Context

Closes #191. Builds on the rescoped #150 (which separated primitives from framework concerns) and supersedes #147 (closed — auto-execution is a framework concern).

Philosophy: Celeste is primitives, not a framework. Tools are a parameter — celeste passes schemas to providers, normalizes responses into ToolCall objects, and returns them. It never auto-executes. This mirrors how the Anthropic SDK, OpenAI SDK, and Google GenAI SDK all work: they return raw tool calls and stop.

Sub-issues

Critical

High

Medium

Low


What changed

Replace three boolean parameters (web_search=True, x_search=True, code_execution=True) with a single tools= list parameter that accepts three tool shapes:

1. Tool classes — server-side tools mapped automatically

from celeste import WebSearch

output = await celeste.text.generate(
    "Search for latest Python release",
    model="claude-4-sonnet",
    tools=[WebSearch(blocked_domains=["reddit.com"])],
)
Tool class Anthropic OpenAI Google xAI
WebSearch web_search_20250305 web_search google_search web_search
XSearch x_search x_search
CodeExecution code_execution code_execution code_execution

2. User-defined function tools — dict with name

from pydantic import BaseModel

class WeatherParams(BaseModel):
    city: str

output = await celeste.text.generate(
    "What is the weather in Paris?",
    model="gpt-4.1",
    tools=[{"name": "get_weather", "description": "Get weather", "parameters": WeatherParams}],
)

output.tool_calls  # [ToolCall(id="call_xxx", name="get_weather", arguments={"city": "Paris"})]

3. Raw passthrough — dict without name

tools=[{"type": "bash_20250124"}]  # Anthropic computer use

Multi-turn tool use

from celeste import ToolResult
from celeste.types import Message, Role

tool_call = output.tool_calls[0]
weather = get_weather(tool_call.arguments["city"])

output2 = await celeste.text.generate(
    model="gpt-4.1",
    messages=[
        Message(role=Role.USER, content="What is the weather in Paris?"),
        Message(role=Role.ASSISTANT, content=output.content),
        ToolResult(content=weather, tool_call_id=tool_call.id, name="get_weather"),
    ],
    tools=[{"name": "get_weather", "description": "Get weather", "parameters": WeatherParams}],
)

Architecture

ToolMapper (parallel to ParameterMapper)

Each provider defines ToolMapper subclasses for the tools it supports. A single ToolsMapper (a ParameterMapper) dispatches to the right ToolMapper based on tool_type.

ToolSupport constraint

Model-level validation. Each model declares which Tool classes it supports:

TextParameter.TOOLS: ToolSupport(tools=[WebSearch, XSearch, CodeExecution])

Output parsing

  • Non-streaming: _parse_tool_calls(response_data) — template method on base ModalityClient
  • Streaming: _aggregate_tool_calls(chunks, raw_events) — template method on base Stream

Migration

# Before
output = await celeste.text.generate("...", model="claude-4-sonnet", web_search=True)

# After
from celeste import WebSearch
output = await celeste.text.generate("...", model="claude-4-sonnet", tools=[WebSearch()])

Test plan

  • 507 unit tests pass
  • All pre-commit hooks pass (ruff, mypy, bandit)
  • Integration: tools=[WebSearch()] on each provider
  • Integration: user-defined function tools with ToolCall parsing
  • Integration: multi-turn ToolResult round-trip

@claude
Copy link

claude bot commented Feb 26, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@Kamilbenkirane
Copy link
Member Author

Code review

Found 1 issue:

  1. Multi-turn tool calling sends malformed assistant messages in OpenAI, xAI, and OpenResponses provider clients. When an assistant Message with tool_calls is passed back for multi-turn (e.g. output1.message), the else branch in _init_request calls msg.model_dump(), which produces {"role": "assistant", "content": "...", "tool_calls": [...]}. The Responses API expects assistant tool calls as separate {"type": "function_call", "name": ..., "arguments": ..., "call_id": ...} items in the input array. The protocol-level serialize_messages() in protocols/openresponses/tools.py handles this correctly (lines 96-113) but the provider-specific clients do not use it.

)
else:
items.append(msg.model_dump())
return {"input": items}

)
else:
items.append(msg.model_dump())
return {"input": items}

)
else:
items.append(msg.model_dump())
return {"input": items}

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Replace individual boolean parameters (web_search, x_search, code_execution)
with a single tools= list parameter that accepts Tool instances, user-defined
dicts, and raw passthrough dicts.

- Add Tool, WebSearch, XSearch, CodeExecution classes with provider-specific
  ToolMappers that translate to wire format
- Add ToolCall on Output and ToolResult(Message) for multi-turn tool use
- Add ToolSupport constraint for model-level tool validation
- Add _parse_tool_calls to all providers (Anthropic, OpenAI, xAI, Google,
  OpenResponses) for non-streaming tool call extraction
- Add _aggregate_tool_calls to streaming for all providers
- Update templates for new tools parameter pattern
- WebSearch (non-streaming + streaming) across all 4 providers
- User-defined function tool with ToolCall parsing across all 4 providers
- xAI XSearch server-side tool
- Fix grok-3-mini model config: remove server-side tool support
  (xAI API only supports server-side tools on grok-4+ family)
… protocols

Add protocol-level shared helpers so providers don't duplicate parsing logic:
- Chat Completions: parse_tool_calls, serialize_messages, ToolsMapper, streaming tool call deltas
- OpenResponses: parse_tool_calls, parse_text_content, serialize_messages
- ToolCall extra="allow" for provider-specific fields (e.g. Google thoughtSignature)
- Accept ToolResult in message lists for multi-turn tool conversations
Mirrors OpenResponsesTextClient — shared generate(), analyze(),
_init_request(), _parse_content(), _parse_tool_calls() for all Chat
Completions providers. DeepSeek, Groq, HuggingFace, Mistral, Moonshot
now inherit from it, keeping only parameter_mappers() and _stream_class()
overrides (Mistral also keeps _parse_content for thinking models).

Also renames parse_text_content → parse_content in OpenResponses tools.
Map WebSearch to browser_search (Groq's native format) and add
ToolSupport constraints to all Groq models. GPT-OSS models support
WebSearch and CodeExecution; others support user-defined function tools only.
…al, Moonshot

Add ToolSupport constraints to all models and ToolsMapper parameter
mappers for the 5 Chat Completions providers. Groq GPT-OSS models
support WebSearch + CodeExecution, Moonshot models support WebSearch,
all others support user-defined function tools only.
@Kamilbenkirane Kamilbenkirane force-pushed the feat/unified-tools-parameter branch from 065a599 to 6ca21dc Compare March 21, 2026 14:50
…ol (#229)

OpenResponses is a protocol, not a provider. The provider-level
`modalities/text/providers/openresponses/` was a parallel hierarchy
that reimplemented tool call parsing inline instead of delegating to
the canonical `parse_tool_calls()` from the protocol layer. The inline
versions were also less robust (KeyError vs .get() with fallback).

OpenAI, xAI, and Ollama now inherit from the protocol-level
`OpenResponsesTextClient`, matching the ChatCompletions pattern where
DeepSeek, Groq, Mistral etc. inherit from `ChatCompletionsTextClient`.

Fixes #219
…#218) (#228)

ToolsMapper.map() silently dropped items that were neither Tool instances
nor dicts (e.g. tools=[WebSearch] without ()). Add InvalidToolError and
else clause in all 4 ToolsMapper implementations.
gpt-4-turbo, gpt-4, gpt-3.5-turbo, and grok-2-vision-1212 all support
tool calling but were missing TextParameter.TOOLS in their parameter
constraints. Added ToolSupport(tools=[]) so they properly advertise
tool support in model metadata.

Fixes #225
- Name the protocol in ChatCompletions error: "not supported by Chat Completions"
- ToolSupport with empty tools list now says "not supported by this model"
  instead of "Supported: []"
Tool mappers now emit UnsupportedParameterWarning when a non-None
WebSearch field (e.g. blocked_domains, max_uses) is not supported by
the target provider. Each mapper declares _supported_fields so new
WebSearch fields automatically trigger warnings on providers that
don't map them.

Closes #231
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.

feat: unified tools= parameter

1 participant