Gemini.Streaming.ToolOrchestrator (GeminiEx v0.3.0)
View SourceGenServer responsible for managing a single, stateful, automatic tool-calling stream.
This orchestrator handles the complex multi-stage streaming process:
- Starts the initial streaming HTTP request to the Gemini API
- Buffers and inspects incoming chunks for function calls
- When function calls are detected, stops the first stream and executes tools
- Starts a second streaming request with the complete history including tool results
- Proxies the final stream events to the original subscriber
The orchestrator maintains state throughout this process and handles errors gracefully.
Summary
Functions
Returns a specification to start this module under a supervisor.
Start a new tool orchestrator for automatic streaming.
Stop the orchestrator and all associated streams.
Subscribe an additional process to receive stream events.
Types
@type orchestrator_state() :: %{ stream_id: String.t(), subscriber_pid: pid(), chat: Gemini.Chat.t(), auth_strategy: :gemini | :vertex_ai, config: keyword(), phase: :awaiting_model_call | :executing_tools | :awaiting_final_response, first_stream_pid: pid() | nil, second_stream_pid: pid() | nil, buffered_chunks: [map()], turn_limit: non_neg_integer(), error: term() | nil }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec start_link(String.t(), pid(), Gemini.Chat.t(), :gemini | :vertex_ai, keyword()) :: GenServer.on_start()
Start a new tool orchestrator for automatic streaming.
Parameters
stream_id
: Unique identifier for this streamsubscriber_pid
: Process to receive final stream eventschat
: Initial chat state with history and optionsauth_strategy
: Authentication strategy to useconfig
: Additional configuration options
Returns
{:ok, pid()}
: Orchestrator started successfully{:error, reason}
: Failed to start orchestrator
@spec stop(pid()) :: :ok
Stop the orchestrator and all associated streams.
Subscribe an additional process to receive stream events.