pub struct CodingAgent { /* private fields */ }Expand description
Implementations§
Source§impl CodingAgent
impl CodingAgent
Sourcepub fn new(
provider: Arc<dyn ModelProvider>,
config: CodingAgentConfig,
) -> Result<Self, CodingAgentError>
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.
Sourcepub fn from_session(
provider: Arc<dyn ModelProvider>,
config: CodingAgentConfig,
session: Session,
) -> Result<Self, CodingAgentError>
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.
Sourcepub fn set_commit_hook(&mut self, hook: Option<CommitHook>)
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.
Sourcepub fn session_mut(&mut self) -> &mut Session
pub fn session_mut(&mut self) -> &mut Session
Mutable access between turns; the engine owns the history only inside a turn.
Sourcepub async fn turn(
&mut self,
input: impl Into<String>,
sink: &mut dyn EventSink,
approval: Arc<dyn Approval>,
) -> Result<ModelOutput, CodingAgentError>
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.
Sourcepub fn save_session_to(&self, path: &impl AsRef<Path>) -> Result<()>
pub fn save_session_to(&self, path: &impl AsRef<Path>) -> Result<()>
Writes the session as pretty JSON to path.
Sourcepub fn load_session_from(path: &impl AsRef<Path>) -> Result<Session>
pub fn load_session_from(path: &impl AsRef<Path>) -> Result<Session>
Reads a session written by CodingAgent::save_session_to.