Skip to main content

AgentTask

Struct AgentTask 

Source
pub struct AgentTask<T> { /* private fields */ }
Expand description

One call of an AgentRole, answering with the T of the role.

The role locks its persona, tools, permission mode, MCP config and output type: none of them has a setter here, and each of these calls does not compile.

The name and cost cap of the role are locked too: no setter of the task changes or removes them, so every task of the role is charged to its counter.

The system prompt is locked:

ⓘ
let _ = Reviewer.task("diff".to_string()).system_prompt("x");

The persona is locked:

ⓘ
let _ = Reviewer.task("diff".to_string()).append_system_prompt("x");

The tools are locked:

ⓘ
let _ = Reviewer.task("diff".to_string()).allow_tool(Tool::Bash);

The permission mode is locked:

ⓘ
let _ = Reviewer
    .task("diff".to_string())
    .permission_mode(PermissionMode::BypassPermissions);

The MCP config is locked:

ⓘ
let _ = Reviewer.task("diff".to_string()).mcp_config("{}");

The output type is locked:

ⓘ
let _ = Reviewer.task("diff".to_string()).output::<Other>();

The role name is locked:

ⓘ
let _ = Reviewer.task("diff".to_string()).role("x");

Taking the raw config with AgentStep::into_config and editing it loses the typed answer (ctx.agent then returns a StepOutput), so there is no silent override.

A call-site override changes the step config, so it changes the hash of the RecordReplayProvider fixture: a fixture recorded for the role defaults does not match an overridden task.

§Examples

let task = Reviewer.task("diff".to_string()).model("haiku").allow_failure();
let config = task.into_config();
assert_eq!(config.model, "haiku");
assert!(config.allow_failure);

Implementations§

Source§

impl<T> AgentTask<T>

Source

pub fn model(self, model: &str) -> Self

Override the model of the role for this call.

§Examples
let config = Reviewer.task("diff".to_string()).model("haiku").into_config();
assert_eq!(config.model, "haiku");
Source

pub fn max_budget_usd(self, budget: f64) -> Self

Override the budget of the role for this call.

§Examples
let config = Reviewer.task("diff".to_string()).max_budget_usd(0.10).into_config();
assert_eq!(config.max_budget_usd, Some(0.10));
Source

pub fn max_turns(self, turns: u32) -> Self

Override the turn limit of the role for this call.

§Examples
let config = Reviewer.task("diff".to_string()).max_turns(6).into_config();
assert_eq!(config.max_turns, Some(6));
Source

pub fn effort(self, effort: Effort) -> Self

Override the effort of the role for this call.

§Examples
let config = Reviewer.task("diff".to_string()).effort(Effort::High).into_config();
assert!(matches!(config.effort, Some(Effort::High)));
Source

pub fn working_dir(self, dir: &str) -> Self

Set the working directory of the call.

§Examples
let config = Reviewer.task("diff".to_string()).working_dir("/repo").into_config();
assert_eq!(config.working_dir.as_deref(), Some("/repo"));
Source

pub fn resume(self, session_id: &str) -> Self

Resume a Claude Code session.

§Examples
let config = Reviewer.task("diff".to_string()).resume("sess").into_config();
assert_eq!(config.resume_session_id.as_deref(), Some("sess"));
Source

pub fn session_id(self, session_id: &str) -> Self

Pin the session id of the call.

§Examples
let config = Reviewer.task("diff".to_string()).session_id("sid").into_config();
assert_eq!(config.session_id.as_deref(), Some("sid"));
Source

pub fn resume_prompt(self, prompt: &str) -> Self

Set the prompt sent when the step is resumed after a lost lease.

§Examples
let config = Reviewer.task("diff".to_string()).resume_prompt("go on").into_config();
assert_eq!(config.resume_prompt.as_deref(), Some("go on"));
Source

pub fn resume_environment(self, environment_id: &str) -> Self

Resume the environment handed out by an earlier step.

§Examples
let config = Reviewer.task("diff".to_string()).resume_environment("env-1").into_config();
assert_eq!(config.resume_environment_id.as_deref(), Some("env-1"));
Source

pub fn retry_policy(self, policy: RetryPolicy) -> Self

Set the retry policy of the step.

§Examples
let config = Reviewer.task("diff".to_string()).retry_policy(RetryPolicy::new(2)).into_config();
assert_eq!(config.retry.map(|r| r.max_retries()), Some(2));
Source

pub fn allow_failure(self) -> Self

Let the run go on when this step fails.

§Examples
let config = Reviewer.task("diff".to_string()).allow_failure().into_config();
assert!(config.allow_failure);
Source

pub fn verbose(self, enabled: bool) -> Self

Record the agent conversation of the call.

§Examples
let config = Reviewer.task("diff".to_string()).verbose(true).into_config();
assert!(config.verbose);
Source

pub fn pod_label(self, key: &str, value: &str) -> Self

Add a label to the pod running the call.

§Examples
let config = Reviewer.task("diff".to_string()).pod_label("team", "qa").into_config();
assert_eq!(config.pod_labels.get("team").map(String::as_str), Some("qa"));
Source

pub fn pod_labels(self, labels: BTreeMap<String, String>) -> Self

Set the labels of the pod running the call.

§Examples
let labels = BTreeMap::from([("team".to_string(), "qa".to_string())]);
let config = Reviewer.task("diff".to_string()).pod_labels(labels.clone()).into_config();
assert_eq!(config.pod_labels, labels);

Trait Implementations§

Source§

impl<T: DeserializeOwned> AgentStep for AgentTask<T>

Source§

type Answer = T

What the step returns to the handler.
Source§

fn into_config(self) -> AgentStepConfig

The configuration, without its typestate.
Source§

fn answer(output: StepOutput) -> Result<T, EngineError>

Read the step output as the answer. Read more
Source§

impl<T> Clone for AgentTask<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for AgentTask<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AgentTask<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for AgentTask<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for AgentTask<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for AgentTask<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for AgentTask<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for AgentTask<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for AgentTask<T>
where PhantomData<fn() -> T>: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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