pub struct TaskContext {
pub forge: Option<Forge>,
pub workflow_id: String,
pub task_id: TaskId,
pub task_timeout: Option<Duration>,
pub tool_registry: Option<Arc<ToolRegistry>>,
pub audit_log: Option<AuditLog>,
/* private fields */
}Expand description
Execution context provided to workflow tasks.
Provides access to the Forge SDK for graph operations, metadata about the current workflow execution, and cancellation token.
Fields§
§forge: Option<Forge>Optional Forge instance for graph queries
workflow_id: StringWorkflow identifier for this execution
task_id: TaskIdTask identifier for this execution
task_timeout: Option<Duration>Optional task timeout duration
tool_registry: Option<Arc<ToolRegistry>>Optional tool registry for tool invocation
audit_log: Option<AuditLog>Optional audit log for recording events (cloned from executor)
Implementations§
Source§impl TaskContext
impl TaskContext
Sourcepub fn with_forge(self, forge: Forge) -> Self
pub fn with_forge(self, forge: Forge) -> Self
Sets the Forge instance for graph operations.
Sourcepub fn with_cancellation_token(self, token: CancellationToken) -> Self
pub fn with_cancellation_token(self, token: CancellationToken) -> Self
Sets the cancellation token for cooperative cancellation.
§Arguments
token- The cancellation token to check during task execution
§Returns
The context with cancellation token set (for builder pattern)
§Example
use forge_agent::workflow::{CancellationTokenSource, TaskContext};
let source = CancellationTokenSource::new();
let context = TaskContext::new("workflow-1", task_id)
.with_cancellation_token(source.token());Sourcepub fn cancellation_token(&self) -> Option<&CancellationToken>
pub fn cancellation_token(&self) -> Option<&CancellationToken>
Returns a reference to the cancellation token if set.
Tasks can use this to check for cancellation during execution.
§Example
async fn execute(&self, context: &TaskContext) -> Result<TaskResult, TaskError> {
if let Some(token) = context.cancellation_token() {
if token.is_cancelled() {
return Ok(TaskResult::Skipped);
}
}
// ... do work
}Sourcepub fn with_task_timeout(self, timeout: Duration) -> Self
pub fn with_task_timeout(self, timeout: Duration) -> Self
Sourcepub fn with_tool_registry(self, registry: Arc<ToolRegistry>) -> Self
pub fn with_tool_registry(self, registry: Arc<ToolRegistry>) -> Self
Sets the tool registry for tool invocation.
§Arguments
registry- The tool registry to use for tool invocation
§Returns
The context with tool registry set (for builder pattern)
§Example
use forge_agent::workflow::tools::ToolRegistry;
use std::sync::Arc;
let registry = Arc::new(ToolRegistry::new());
let context = TaskContext::new("workflow-1", task_id)
.with_tool_registry(registry);Sourcepub fn tool_registry(&self) -> Option<&Arc<ToolRegistry>>
pub fn tool_registry(&self) -> Option<&Arc<ToolRegistry>>
Sourcepub fn with_audit_log(self, audit_log: AuditLog) -> Self
pub fn with_audit_log(self, audit_log: AuditLog) -> Self
Sets the audit log for event recording.
§Arguments
audit_log- The audit log to use for event recording
§Returns
The context with audit log set (for builder pattern)
§Example
use forge_agent::audit::AuditLog;
let audit_log = AuditLog::new();
let context = TaskContext::new("workflow-1", task_id)
.with_audit_log(audit_log);Sourcepub fn audit_log_mut(&mut self) -> Option<&mut AuditLog>
pub fn audit_log_mut(&mut self) -> Option<&mut AuditLog>
Trait Implementations§
Source§impl Clone for TaskContext
impl Clone for TaskContext
Source§fn clone(&self) -> TaskContext
fn clone(&self) -> TaskContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TaskContext
impl RefUnwindSafe for TaskContext
impl Send for TaskContext
impl Sync for TaskContext
impl Unpin for TaskContext
impl UnsafeUnpin for TaskContext
impl UnwindSafe for TaskContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more