pub trait ToolModel:
Send
+ Sync
+ 'static {
// Required methods
fn model_name(&self) -> &str;
fn provider_name(&self) -> &str;
fn complete<'a>(
&'a self,
request: ChatRequest<'a>,
) -> Pin<Box<dyn Future<Output = Result<ModelTurn, ModelError>> + Send + 'a>>;
// Provided methods
fn server(&self) -> Option<(&str, u16)> { ... }
fn complete_streaming<'a>(
&'a self,
request: ChatRequest<'a>,
text: &'a TextSink,
) -> Pin<Box<dyn Future<Output = Result<ModelTurn, ModelError>> + Send + 'a>> { ... }
}tool-loop only.Expand description
One completion turn of a model that can call tools.
Object-safe, with boxed futures, like AgentExecutor:
ToolLoop holds it as a Box<dyn ToolModel>.
An implementation sends the request once and reports what came back. It
does not run tools, retry or loop; ToolLoop does.
LimitedModel wraps one to bound how many turns
are in flight at once.
Required Methods§
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
The model asked for, recorded as gen_ai.request.model and in the
name of each turn’s span (chat {model}).
Sourcefn provider_name(&self) -> &str
fn provider_name(&self) -> &str
The provider, recorded as gen_ai.provider.name: one of the
GenAI conventions’ well-known values (openai, anthropic,
gcp.gemini, …) when one applies.
Sourcefn complete<'a>(
&'a self,
request: ChatRequest<'a>,
) -> Pin<Box<dyn Future<Output = Result<ModelTurn, ModelError>> + Send + 'a>>
fn complete<'a>( &'a self, request: ChatRequest<'a>, ) -> Pin<Box<dyn Future<Output = Result<ModelTurn, ModelError>> + Send + 'a>>
Runs one turn.
§Errors
A ModelError when the provider failed. The loop ends the task on
it, except that a loop given
with_model_retry sends the
turn again after a RateLimited.
Provided Methods§
Sourcefn server(&self) -> Option<(&str, u16)>
fn server(&self) -> Option<(&str, u16)>
Where the provider is served, as a host and port, recorded as
server.address and server.port. None, the default, records
neither: a model running in this process has no server.
Sourcefn complete_streaming<'a>(
&'a self,
request: ChatRequest<'a>,
text: &'a TextSink,
) -> Pin<Box<dyn Future<Output = Result<ModelTurn, ModelError>> + Send + 'a>>
fn complete_streaming<'a>( &'a self, request: ChatRequest<'a>, text: &'a TextSink, ) -> Pin<Box<dyn Future<Output = Result<ModelTurn, ModelError>> + Send + 'a>>
Runs one turn as complete does, and hands
text each piece of the turn’s text as the provider sends it, so a
caller can watch a long answer arrive (audit L5). The turn it
returns is the whole of it, its text the pieces joined.
The default runs complete and sends no piece: a
model that cannot stream still works, and its turns arrive whole.
OpenAiChatModel streams.
§Errors
As complete.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".