Expand description
The agent turn loop.
Implements the standard function-calling loop: call the provider; while it
asks for tools, execute them and feed the results back; repeat until the
model ends its turn. Provider streaming chunks are folded into a turn via
polyc_llm::turn::collect_turn; the assistant/tool messages are
mapped to wire Messages for the control plane.
Re-exports§
pub use approval_resolve::ApprovalOverride;pub use approval_resolve::ResolvedCall;pub use approval_resolve::resolve_approved_call;pub use delegate::DELEGATE_TOOL_NAME;pub use delegate::DelegateDescriptor;pub use delegate::DelegateRequest;pub use delegate::delegate_tool_spec;pub use delegate::find_descriptor as find_delegate_descriptor;pub use delegate::parse_delegate_args;pub use handoff::DEFAULT_MAX_CARRY;pub use handoff::HANDOFF_TOOL_NAME;pub use handoff::HandoffRequest;pub use handoff::handoff_tool_spec;pub use handoff::parse_handoff_args;pub use llm_summarizer::LlmSummarizer;pub use step::CircuitBreaker;pub use step::ForcedCompletion;pub use step::ResumePrePass;pub use step::StepOutcome;pub use step::TurnCtx;pub use step::TurnStep;
Modules§
- approval_
resolve - Resolving an approver’s in-flight edit onto the call that executes.
- delegate
- Delegation (in-process sub-agent task) primitive for the agent turn loop.
- extraction
- The provider-agnostic post-turn memory extractor (docs/design/personas.md §5, issue #214).
- handoff
- Handoff (sub-agent transfer) primitive for the agent turn loop.
- identifiers
- Normative identifier extraction for compaction retention (INV-C2).
- identity
- The anchored agent identity block.
- llm_
summarizer - LLM-backed anchored-iterative
Summarizer. - participation
- The provider-agnostic “should the agent speak?” classifier.
- retry
- Bounded retry for the model call with exponential backoff + jitter.
- step
- The
TurnStepseam: a small, ordered set of composable steps the turn loop drives, each owning one cohesive slice of turn behavior.
Structs§
- Delegate
Record - One
__delegate_tocall this turn dispatched (#872) — the forensic record of a worker sub-agent invocation. - Dispatch
Mutation - A dispatch-time mutation a policy applied to an in-flight call (
#67). - Grant
Replay Clear - A single gate clear a remembered grant was solely responsible for (
#594). - MidStream
Failure - A provider stream failure mid-turn, captured onto
TurnResultinstead of propagated as anErr(#798) — seeTurnResult::mid_stream_failure. - Pending
Approval - One tool call awaiting human-in-the-loop approval.
- Remembered
Grant - A verified remembered grant a turn runs under, keyed by tool in
RunTurnOptions::remembered_grants(#594). - RunTurn
Options - Options for a single
run_turninvocation. - Stub
Summarizer - Deterministic placeholder summarizer — formats a tiny excerpt of the transcript so the data path is exercisable without a provider. Real deployments swap in an LLM-backed summarizer (one-trait swap).
- Stub
Tools - Placeholder executor: advertises no tools and reports any call it receives as unhandled (the model shouldn’t call anything without specs, but the guard keeps the loop progressing if it does).
- Turn
Result - Output of one
run_turncall. - Unattended
Denial - A single gated call an unattended turn denied fail-closed (
#623).
Enums§
- Dispatch
Mutation Kind - The specific dispatch mutation carried by a
DispatchMutation. - Tool
Decision - The argument-aware dispatch-policy decision for one tool call (
#67). - Turn
Stream Event - Re-export so callers can build a streaming channel without depending on
polyc-llmdirectly. An incremental event observed while folding a turn, for live streaming.
Traits§
- Dispatch
Recorder - Signs + durably records a dispatch mutation before it applies (
#67). - Summarizer
- Produces a textual summary of a transcript chunk that’s about to be
dropped from the prompt window. Implementations can be deterministic
(the
StubSummarizer) or LLM-backed (a follow-up). - Tool
Executor - Executes a tool call by name, returning a JSON result string. Also advertises the tools it can execute so the provider knows what’s callable.
Functions§
- current_
tool_ call_ id - Returns the provider-assigned id of the tool call currently executing, when
called from within a
run_turn_withtool execution;Noneoutside that scope. - internal_
note_ message - Build an
internal_onlysystemMessagecarrying context an approver (or, later, a policy gate) injected before a tool runs (#67). - llm_
stop_ to_ wire_ i32 - Map an
llm-sideStopReasonto the wire enum value. - llm_
to_ wire - Convert an llm
LlmMessageinto wireMessages for transmission overHarnessService. - mark_
result_ untrusted - Marks the currently-executing tool call’s result as carrying untrusted content, overriding the static per-tool-name provenance check for THIS call only.
- resolve_
default_ max_ steps - Resolve this deployment’s step-budget baseline.
- run_
turn - Run one agent turn to completion with no caller-supplied options (the
common path; equivalent to
run_turn_with(..., RunTurnOptions::default())). - run_
turn_ with - Run one agent turn to completion with caller-supplied
RunTurnOptions. - text_
message - Build a wire
Messagecarrying a single text content block. - thought_
message - Build a
model-roleMessagecarrying model reasoning as aThoughtContent, NOT as answer text. - tool_
call_ message - Build a wire
Messagecarrying a structured tool call. - tool_
result_ message - Build a wire
Messagecarrying a structured tool result keyed to its originatingcall_id. - wire_
to_ llm - Convert an owned wire
Messageinto an llmLlmMessage. - wire_
to_ llm_ stop - Inverse of
llm_stop_to_wire_i32: lift a wire enum value back. - with_
tool_ call_ id - Runs
futwithcurrent_tool_call_idset toidfor its duration. - with_
untrusted_ result_ capture - Runs one tool execution and captures whether it called
mark_result_untrusted, returning the execution’s output alongside the flag.