gleamstral/agent
Types
Represents an agent with configuration options for communication with Mistral AI agents
pub type Agent {
Agent(client: client.Client, config: Config)
}
Constructors
-
Agent(client: client.Client, config: Config)
pub type ChatCompletionChoice {
ChatCompletionChoice(
index: Int,
message: message.Message,
finish_reason: FinishReason,
)
}
Constructors
-
ChatCompletionChoice( index: Int, message: message.Message, finish_reason: FinishReason, )
pub type Config {
Config(
max_tokens: Int,
stream: Bool,
stop: List(String),
random_seed: Int,
response_format: ResponseFormat,
tools: List(tool.Tool),
tool_choice: tool.ToolChoice,
presence_penalty: Float,
frequency_penalty: Float,
n: Int,
prediction: Prediction,
)
}
Constructors
-
Config( max_tokens: Int, stream: Bool, stop: List(String), random_seed: Int, response_format: ResponseFormat, tools: List(tool.Tool), tool_choice: tool.ToolChoice, presence_penalty: Float, frequency_penalty: Float, n: Int, prediction: Prediction, )
pub type FinishReason {
Stop
Length
ModelLength
Err
ToolCalls
}
Constructors
-
Stop
-
Length
-
ModelLength
-
Err
-
ToolCalls
pub type Prediction {
Content(String)
}
Constructors
-
Content(String)
pub type Response {
Response(
id: String,
object: String,
created: Int,
model: String,
choices: List(ChatCompletionChoice),
usage: Usage,
)
}
Constructors
-
Response( id: String, object: String, created: Int, model: String, choices: List(ChatCompletionChoice), usage: Usage, )
pub type ResponseFormat {
JsonObject
Text
}
Constructors
-
JsonObject
-
Text
Functions
pub fn complete_request(
agent: Agent,
agent_id: String,
messages: List(Message),
) -> Request(String)
Creates an HTTP request for the Agent API endpoint
This function prepares a request to be sent to the Mistral AI Agent API. It needs to be paired with an HTTP client to actually send the request, and the response should be handled with client.handle_response using the appropriate decoder.
Example
// Create the request
let req = agent
|> agent.complete_request("agent-123", messages)
// Send the request with your HTTP client
use response <- result.try(http_client.send(req))
// Handle the response with the appropriate decoder
client.handle_response(response, using: agent.response_decoder())
pub fn handle_response(
response: Response(String),
) -> Result(gleamstral/agent.Response, Error)
Handle HTTP responses from an agent request
This is a convenience function that automatically uses the agent response decoder, so you don’t need to pass it manually.
Example
agent.handle_response(response)
pub fn new(client: Client) -> Agent
Creates a new Agent with default configuration using the provided client
Example
let client = client.new("your-api-key")
let agent = agent.new(client)
pub fn response_decoder() -> Decoder(Response)
pub fn set_frequency_penalty(
agent: Agent,
frequency_penalty: Float,
) -> Agent
pub fn set_max_tokens(agent: Agent, max_tokens: Int) -> Agent
pub fn set_prediction(
agent: Agent,
prediction: Prediction,
) -> Agent
pub fn set_presence_penalty(
agent: Agent,
presence_penalty: Float,
) -> Agent
pub fn set_random_seed(agent: Agent, random_seed: Int) -> Agent
pub fn set_response_format(
agent: Agent,
response_format: ResponseFormat,
) -> Agent
pub fn set_stream(agent: Agent, stream: Bool) -> Agent
pub fn set_tool_choice(
agent: Agent,
tool_choice: ToolChoice,
) -> Agent