Skip to main content

Crate agent_line

Crate agent_line 

Source
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.)
ErrorEvent
Passed to the on_error hook when an agent errors or a limit is exceeded.
RetryHint
Metadata attached to an Outcome::Retry to explain why the agent wants to retry.
Runner
Executes a Workflow step by step, handling retries, waits, and routing.
StepEvent
Passed to the on_step hook after each successful agent step.
Workflow
A validated workflow of agents. Built via Workflow::builder.
WorkflowBuilder
Step-by-step builder for a Workflow. Obtained via Workflow::builder.

Enums§

Outcome
Control flow for the runner.
StepError
Error type for agent steps, with variants designed around what the caller can do about them.
WorkflowError
Errors returned by WorkflowBuilder::build.

Traits§

Agent
A sync agent that transforms state one step at a time.

Type Aliases§

StepResult
The result of running a step: a new state plus what to do next.