Skip to main content

Crate polyc_agent

Crate polyc_agent 

Source
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 TurnStep seam: a small, ordered set of composable steps the turn loop drives, each owning one cohesive slice of turn behavior.

Structs§

DelegateRecord
One __delegate_to call this turn dispatched (#872) — the forensic record of a worker sub-agent invocation.
DispatchMutation
A dispatch-time mutation a policy applied to an in-flight call (#67).
GrantReplayClear
A single gate clear a remembered grant was solely responsible for (#594).
MidStreamFailure
A provider stream failure mid-turn, captured onto TurnResult instead of propagated as an Err (#798) — see TurnResult::mid_stream_failure.
PendingApproval
One tool call awaiting human-in-the-loop approval.
RememberedGrant
A verified remembered grant a turn runs under, keyed by tool in RunTurnOptions::remembered_grants (#594).
RunTurnOptions
Options for a single run_turn invocation.
StubSummarizer
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).
StubTools
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).
TurnResult
Output of one run_turn call.
UnattendedDenial
A single gated call an unattended turn denied fail-closed (#623).

Enums§

DispatchMutationKind
The specific dispatch mutation carried by a DispatchMutation.
ToolDecision
The argument-aware dispatch-policy decision for one tool call (#67).
TurnStreamEvent
Re-export so callers can build a streaming channel without depending on polyc-llm directly. An incremental event observed while folding a turn, for live streaming.

Traits§

DispatchRecorder
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).
ToolExecutor
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_with tool execution; None outside that scope.
internal_note_message
Build an internal_only system Message carrying context an approver (or, later, a policy gate) injected before a tool runs (#67).
llm_stop_to_wire_i32
Map an llm-side StopReason to the wire enum value.
llm_to_wire
Convert an llm LlmMessage into wire Messages for transmission over HarnessService.
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 Message carrying a single text content block.
thought_message
Build a model-role Message carrying model reasoning as a ThoughtContent, NOT as answer text.
tool_call_message
Build a wire Message carrying a structured tool call.
tool_result_message
Build a wire Message carrying a structured tool result keyed to its originating call_id.
wire_to_llm
Convert an owned wire Message into an llm LlmMessage.
wire_to_llm_stop
Inverse of llm_stop_to_wire_i32: lift a wire enum value back.
with_tool_call_id
Runs fut with current_tool_call_id set to id for 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.