Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx { /* private fields */ }
Expand description

Execution context shared across all agents in a workflow.

Ctx carries two things:

  • a string key-value store for cross-agent data,
  • an append-only event log for diagnostic messages.

State is not reset between crate::Runner::run calls, so the store and log accumulate across runs unless cleared explicitly with clear_logs or clear.

LLM access lives on crate::LlmConfig, not on Ctx. Agents that need an LLM hold their own crate::LlmConfig and call crate::LlmConfig::request to start a chat request.

Implementations§

Source§

impl Ctx

Source

pub fn new() -> Self

Create a new empty context (KV store and event log).

Source

pub fn set(&mut self, key: impl Into<String>, value: impl Into<String>)

Insert or overwrite a key in the KV store.

Source

pub fn get(&self, key: &str) -> Option<&str>

Look up a key in the KV store.

Source

pub fn remove(&mut self, key: &str) -> Option<String>

Remove a key from the KV store, returning its value if it existed.

Source

pub fn log(&mut self, msg: impl Into<String>)

Append a message to the event log.

Source

pub fn logs(&self) -> &[String]

Return all log messages in order.

Source

pub fn clear_logs(&mut self)

Clear the event log, leaving the KV store intact.

Source

pub fn clear(&mut self)

Clear both the KV store and the event log.

Trait Implementations§

Source§

impl Default for Ctx

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Ctx

§

impl RefUnwindSafe for Ctx

§

impl Send for Ctx

§

impl Sync for Ctx

§

impl Unpin for Ctx

§

impl UnsafeUnpin for Ctx

§

impl UnwindSafe for Ctx

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.