Skip to content

feat(gemini): Phase 3 -- tool use / function calling #1595

@bug-ops

Description

@bug-ops

Part of #1592

Scope

Implement native function calling for Gemini via tools + functionDeclarations.

Files to Modify

  • crates/zeph-llm/src/gemini.rs -- implement chat_with_tools(), tool definition conversion, tool result handling

Key Implementation Details

Tool Definition Conversion (Zeph -> Gemini)

Zeph ToolDefinition maps to Gemini functionDeclarations:

  • JSON Schema type names must be UPPERCASED: string -> STRING, object -> OBJECT, etc.
  • $ref / $defs references must be inlined (Gemini does not support JSON Schema references)
  • Nested in tools[0].functionDeclarations[] (not flat like OpenAI)

Tool Call Parsing (Gemini -> Zeph)

Gemini returns functionCall as a part in candidates[0].content.parts[]:

{ "functionCall": { "name": "tool_name", "args": {...} } }

Map to ToolUseRequest { id: generated_uuid, name, input: args }.
Note: Gemini does not return a tool call ID -- generate a UUID locally.

Tool Result Format (Zeph -> Gemini)

Tool results are sent as functionResponse parts in a user message:

{ "role": "user", "parts": [{ "functionResponse": { "name": "...", "response": {...} } }] }

Tool Config

Send toolConfig.functionCallingConfig.mode as "AUTO" (default).

Acceptance Criteria

  • supports_tool_use() returns true
  • chat_with_tools() sends correctly formatted function declarations
  • Single and multi-tool call responses parsed into ChatResponse::ToolUse
  • Tool results sent back as functionResponse parts
  • JSON Schema type names uppercased in conversion
  • $ref / $defs inlined in schema conversion
  • UUID generated for tool call IDs (Gemini does not provide them)
  • Unit tests for tool format conversion edge cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions