pub struct Runtime {
pub model: Option<String>,
pub api_key: Option<String>,
pub used: bool,
/* private fields */
}Expand description
Runtime - Main execution environment for agentic functions
Fields§
§model: Option<String>§api_key: Option<String>§used: boolImplementations§
Source§impl Runtime
impl Runtime
Sourcepub fn with_config(model: Option<String>, api_key: Option<String>) -> Self
pub fn with_config(model: Option<String>, api_key: Option<String>) -> Self
Create a Runtime with specific configuration
Sourcepub async fn register_tool(
&self,
name: impl Into<String>,
tool_fn: ToolFunction,
tool_type: Option<String>,
) -> Result<()>
pub async fn register_tool( &self, name: impl Into<String>, tool_fn: ToolFunction, tool_type: Option<String>, ) -> Result<()>
Register a tool function
§Arguments
name- Tool name for LLMtool_fn- Sync or async functiontool_type- Optional type name for marshalling
Sourcepub async fn register_tool_with_schema(
&self,
name: impl Into<String>,
description: impl Into<String>,
schema: Value,
tool_fn: ToolFunction,
) -> Result<()>
pub async fn register_tool_with_schema( &self, name: impl Into<String>, description: impl Into<String>, schema: Value, tool_fn: ToolFunction, ) -> Result<()>
Register a tool function with schema information
This method is useful when you have a tool struct that provides its schema
via #[derive(Tool)], and you want to register it with a handler function.
§Arguments
name- Tool name for LLMdescription- Tool descriptionschema- JSON schema for the tool parameters (from Tool::schema())tool_fn- Sync or async function to handle the tool call
§Example
runtime.register_tool_with_schema(
MyTool::tool_name(),
MyTool::description(),
MyTool::schema(),
ToolFunction::Sync(Box::new(|args| {
// Handle the tool call
Ok("result".to_string())
})),
).await?;Sourcepub async fn tool<T, F>(&self, handler: F, name: Option<&str>) -> Result<()>
pub async fn tool<T, F>(&self, handler: F, name: Option<&str>) -> Result<()>
Register a tool with type and handler (Python: runtime.tool(fn, name=…, tool_type=…))
This is the primary API for registering tools for native tool calling. The type parameter T must implement Deserializable. The handler receives the typed struct directly - deserialization is handled automatically.
§Arguments
handler- Async function that receives the typed struct Tname- Optional tool name (defaults to type name if None)
§Example
#[derive(Deserialize, Serialize)]
struct WeatherQuery {
city: String,
units: Option<String>,
}
impl Deserializable for WeatherQuery { ... }
// Handler receives WeatherQuery directly, not raw JSON
runtime.tool::<WeatherQuery, _>(|query| Box::pin(async move {
Ok(format!("Weather in {}: Sunny", query.city))
}), Some("get_weather")).await?;Sourcepub async fn get_parser(&self) -> NativeToolParser
pub async fn get_parser(&self) -> NativeToolParser
Get a NativeToolParser instance with all registered tool constructors
This parser can be used during streaming to dynamically construct ParsedTool instances from tool call deltas.
Sourcepub async fn get_tool_schemas(&self) -> HashMap<String, ToolSchemaInfo>
pub async fn get_tool_schemas(&self) -> HashMap<String, ToolSchemaInfo>
Get tool schema information for all registered tools
Sourcepub async fn run(&mut self, params: RunParams) -> Result<Value>
pub async fn run(&mut self, params: RunParams) -> Result<Value>
Execute a non-streaming LLM call
Sourcepub async fn run_stream(
&mut self,
params: RunParams,
) -> Result<impl Stream<Item = Result<(String, Value)>>>
pub async fn run_stream( &mut self, params: RunParams, ) -> Result<impl Stream<Item = Result<(String, Value)>>>
Execute a streaming LLM call
Returns an async stream of (chunk_type, chunk_value) tuples
Sourcepub fn is_tool_call(&self, result: &Value) -> bool
pub fn is_tool_call(&self, result: &Value) -> bool
Check if a result is a tool call
Sourcepub fn get_tool_name(&self, result: &Value) -> Option<String>
pub fn get_tool_name(&self, result: &Value) -> Option<String>
Get tool name from result
Sourcepub async fn execute_tool(&self, tool_result: &Value) -> Result<String>
pub async fn execute_tool(&self, tool_result: &Value) -> Result<String>
Execute a tool call
Sourcepub async fn raw_response(&self) -> String
pub async fn raw_response(&self) -> String
Get accumulated raw response
Sourcepub async fn reasoning_segments(&self) -> Vec<ReasoningSegment>
pub async fn reasoning_segments(&self) -> Vec<ReasoningSegment>
Get reasoning segments
Sourcepub async fn clear_raw_response(&self)
pub async fn clear_raw_response(&self)
Clear raw response accumulator
Sourcepub async fn clear_reasoning(&self)
pub async fn clear_reasoning(&self)
Clear reasoning accumulator
Sourcepub async fn clear_reasoning_segments(&self)
pub async fn clear_reasoning_segments(&self)
Clear reasoning segments
Sourcepub async fn set_default_prompt(&self, prompt: impl Into<String>)
pub async fn set_default_prompt(&self, prompt: impl Into<String>)
Set default prompt (from function docstring)
Sourcepub async fn set_return_type(&self, type_name: Option<String>)
pub async fn set_return_type(&self, type_name: Option<String>)
Set return type