On this page
AgentExecutionMixin runs orchestrator and agent tasks end-to-end: session creation, prompt assembly, context-window checks, agent handoff, tool building, and attempt completion/timeout handling.
#scheduler.src.orxtra.scheduler._agent_execution
#scheduler.src.orxtra.scheduler._agent_execution
#_resolve_task_variables
def _resolve_task_variables(template: str, variables: dict[str, Any] | None) -> strResolve variables in a task prompt template.
Wraps compose's strict resolve_variables with two adaptations for the scheduler's workflow context:
- Values are coerced to str (callers pass dict[str, Any]).
- Unused variables are filtered out rather than rejected,
because the workflow executor accumulates all dependency outputs as variables and tasks use only a subset.
Unresolved placeholders still raise ValueError (catches typos in task prompts).
#_deferred_stub_execute
async def _deferred_stub_execute(args: dict[str, Any]) -> ToolOutput[Any]Placeholder execute for deferred tool stubs.
If called, the LLM tried to use the tool before loading it.
#AgentExecutionMixin
Mixin for agent and orchestrator task execution.
#_execute_orchestrator_task
async def _execute_orchestrator_task(self, task: TaskSpec, task_id: UUID, parent_task_id: UUID | None, variables: dict[str, Any] | None=None) -> TaskResultExecute an orchestrator task with multi-turn suspension support.
#_execute_orchestrator_or_agent_task
async def _execute_orchestrator_or_agent_task(self, task: TaskSpec, task_id: UUID, parent_task_id: UUID | None, variables: dict[str, Any] | None) -> TaskResultDispatch to orchestrator or agent task execution.
#_compute_context_usage
def _compute_context_usage(self, session: Session) -> tuple[int, float]Compute total tokens used and usage percentage of context limit.
Returns (tokens_used, usage_percent).
#_check_agent_context
async def _check_agent_context(self, session: Session, session_id: str, task_id: UUID) -> NoneCheck agent session context usage and emit warnings or trigger handoff.
Emits ContextWarning at 80% usage. Triggers handoff at 90%.
#_agent_handoff
async def _agent_handoff(self, session: Session, task_id: UUID) -> NonePerform agent context handoff: summarize conversation, create new session.
Asks the current session to summarize, then creates a fresh session with the summary as initial context. Replaces the session in _task_sessions.
#_build_agent_tools
def _build_agent_tools(self, agent_def: Agent, task_id: UUID, session_id: str, task_name: str, task_agent: str) -> list[Tool]Build raw tools based on agent's allow list.
Uses the ToolRegistry for data-driven construction of standard tools, with special handling for git (subcommand resolution), consult (needs already-built tools), inline tool definitions (per-agent [[tools.define]]), deferred tools (stubs + load_tools auto-grant), and lifecycle tools (always present).
#_assemble_agent_prompt
async def _assemble_agent_prompt(self, task: TaskSpec, task_id: UUID, variables: dict[str, Any] | None, attempt: int, attempt_id: UUID, prior_attempts: list[dict[str, Any]]) -> strAssemble full prompt with runtime context layers.
Uses the compose engine with fragment providers for each layer. Variable substitution in the task prompt uses strict resolution: unresolved placeholders raise ValueError. Unused variables are filtered (workflow executor accumulates dependency outputs).
#_refresh_injection_data
async def _refresh_injection_data(self) -> NoneRefresh constraints, lessons, and notepad from trace.
Called at the start of each task attempt, before prompt assembly. Each callback replaces the scheduler's in-memory list with fresh data from the storage backend.
When no callbacks are registered (default), the lists remain as initialized (empty or manually populated).