pub struct LlmAgent { /* private fields */ }Expand description
An Agent that answers with an OpenAI-compatible model, and can call one
tool on the way.
let agent = LlmAgent::from_env().expect("AG_UI_LLM_API_KEY");
let app: axum::Router = axum::Router::new().route_agui("/agent", agent);Implementations§
Source§impl LlmAgent
impl LlmAgent
Sourcepub fn new(
base_url: impl Into<String>,
model: impl Into<String>,
api_key: Option<String>,
) -> Self
pub fn new( base_url: impl Into<String>, model: impl Into<String>, api_key: Option<String>, ) -> Self
An agent pointed at base_url, talking to model.
api_key is None for an endpoint that wants no credential, which is
the usual case for a model served on localhost.
Sourcepub fn from_env() -> Result<Self, MissingApiKey>
pub fn from_env() -> Result<Self, MissingApiKey>
An agent configured from the environment.
| Variable | Default |
|---|---|
BASE_URL_ENV | DEFAULT_BASE_URL |
MODEL_ENV | DEFAULT_MODEL |
API_KEY_ENV, then FALLBACK_API_KEY_ENV | none |
§Errors
MissingApiKey when no key is set and the endpoint is the default
one, which needs one. A custom BASE_URL_ENV is taken to mean a
server the caller runs, so a missing key there is not an error — it is
sent as absent.
Sourcepub fn model_name(&self) -> &str
pub fn model_name(&self) -> &str
The model this agent is pointed at.
Trait Implementations§
Source§impl Agent for LlmAgent
impl Agent for LlmAgent
Source§type State = ()
type State = ()
The run’s shared state, deserialized from
RunAgentInput::state and published
through RunContext::set_state.Source§async fn run(&self, ctx: &mut RunContext<()>) -> Result<RunOutcome>
async fn run(&self, ctx: &mut RunContext<()>) -> Result<RunOutcome>
Serves one run. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for LlmAgent
impl !UnwindSafe for LlmAgent
impl Freeze for LlmAgent
impl Send for LlmAgent
impl Sync for LlmAgent
impl Unpin for LlmAgent
impl UnsafeUnpin for LlmAgent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more