Expand description
A batteries-included Rust library for building agent workflows.
Define agents, wire them into workflows, and let the runner execute them.
Agents communicate through shared context (Ctx) and control flow with
outcomes like Outcome::Continue, Outcome::Next, Outcome::Retry,
and Outcome::Done.
§Quick start
use agent_line::{Agent, Ctx, Outcome, Runner, StepResult, Workflow};
#[derive(Clone)]
struct State { n: i32 }
struct AddOne;
impl Agent<State> for AddOne {
fn name(&self) -> &'static str { "add_one" }
fn run(&mut self, state: State, _ctx: &mut Ctx) -> StepResult<State> {
Ok((State { n: state.n + 1 }, Outcome::Done))
}
}
let mut ctx = Ctx::new();
let wf = Workflow::builder("demo")
.register(AddOne)
.build()
.unwrap();
let result = Runner::new(wf).run(State { n: 0 }, &mut ctx).unwrap();
assert_eq!(result.n, 1);Modules§
- tools
- Standalone utility functions for common agent tasks.
Structs§
- Ctx
- Execution context for agents (services, config, etc.)
- Error
Event - Passed to the
on_errorhook when an agent errors or a limit is exceeded. - Retry
Hint - Metadata attached to an
Outcome::Retryto explain why the agent wants to retry. - Runner
- Executes a
Workflowstep by step, handling retries, waits, and routing. - Step
Event - Passed to the
on_stephook after each successful agent step. - Workflow
- A validated workflow of agents. Built via
Workflow::builder. - Workflow
Builder - Step-by-step builder for a
Workflow. Obtained viaWorkflow::builder.
Enums§
- Outcome
- Control flow for the runner.
- Step
Error - Error type for agent steps, with variants designed around what the caller can do about them.
- Workflow
Error - Errors returned by
WorkflowBuilder::build.
Traits§
- Agent
- A sync agent that transforms state one step at a time.
Type Aliases§
- Step
Result - The result of running a step: a new state plus what to do next.