Skip to main content

CodingAgent

Struct CodingAgent 

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

A coding agent: drives run_turn over the built-in tools, one turn at a time, keeping the history in a caller-visible Session.

Implementations§

Source§

impl CodingAgent

Source

pub fn new( provider: Arc<dyn ModelProvider>, config: CodingAgentConfig, ) -> Result<Self, CodingAgentError>

A fresh agent with an empty session. The workspace is canonicalized for tool scoping; the system prompt defaults to the built-in template rendered by [crate::prompt::render_system] unless config.system replaces it. A base prompt that fails to render fails the construction.

Source

pub fn from_session( provider: Arc<dyn ModelProvider>, config: CodingAgentConfig, session: Session, ) -> Result<Self, CodingAgentError>

A fresh agent resuming session (e.g. from CodingAgent::load_session_from); the next turn continues the prior history.

Source

pub fn set_commit_hook(&mut self, hook: Option<CommitHook>)

Installs the commit-before-execute hook on the engine (see rhema_core::CommitHook); None disables it. A driver that persists the session sets this so a crash inside a tool call leaves a committed intent — which the next turn’s revive closes — rather than no record at all.

Source

pub fn session(&self) -> &Session

The conversation so far.

Source

pub fn system(&self) -> &str

The rendered system prompt this agent stamps into every request.

Source

pub fn session_mut(&mut self) -> &mut Session

Mutable access between turns; the engine owns the history only inside a turn.

Source

pub async fn turn( &mut self, input: impl Into<String>, sink: &mut dyn EventSink, approval: Arc<dyn Approval>, ) -> Result<ModelOutput, CodingAgentError>

One turn: push the user input, loop steps until the model stops requesting tools (capped at max_turn_steps), with approval gating the side-effecting tools. Appends to the session in place; the hook is cleared on the way out, success or failure. A history entering with unanswered calls — a crash resume — revives first, so the model sees a closed round, not a dangling one.

Source

pub fn save_session_to(&self, path: &impl AsRef<Path>) -> Result<()>

Writes the session as pretty JSON to path.

Source

pub fn load_session_from(path: &impl AsRef<Path>) -> Result<Session>

Reads a session written by CodingAgent::save_session_to.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more