Skip to content

crp.agent_sdk

Auto-generated reference for the crp.agent_sdk subpackage.

agent_sdk

crp.agent_sdk

CRPv6 Agent SDK - declarative agents with zero loop code (SPEC-059).

Agent

Declarative agent: tools + policy + model (SPEC-059 §2).

Example::

import crp

def get_weather(city: str) -> dict:
    return {"city": city, "temp": 22}

agent = crp.Agent(model="local/llama3.1", tools=[get_weather])
result = agent.run("What's the weather in Sydney?")
print(result.answer)

register_tool(tool)

Register an additional tool and return self for chaining.

run(user_request, **kwargs)

Run the agent on user_request and return the full response.

ask(question, **kwargs)

Alias for :meth:run optimized for question-answering.

run_stream(user_request, **kwargs)

Run the agent and yield each transparency event as it occurs.

The model calls run in a background thread so events can be consumed incrementally.

run_tel(user_request, **kwargs)

Run the agent and yield AG-UI-compatible transparency events.

This is the public transparency stream consumed by frontends, CLIs, and audit consumers. It wraps :meth:_run in a background thread, maps internal :class:AgentEvent objects to AG-UI events, and adds CRP governance events (quality, provenance, state snapshot).

AgentResponse dataclass

Result of one agent run.

answer property

Human-readable answer text.

sources property

Tool observations surfaced as sources.

decisions property

Decisions recorded in the CSO.

how_it_was_built property

Short narrative of the operation sequence.

open_questions property

Open questions carried forward in the CSO.

complete property

True when the run finished without halting and the plan was integrated.

AgentEvent dataclass

A single event in the agent run stream.

to_dict()

Render as a JSON-serialisable dict.

AgentEventKind

Bases: str, Enum

Canonical agent lifecycle events (SPEC-056 §4.1).

Policy dataclass

Declarative safety/policy constraints for an agent run.

balanced() classmethod

Balanced policy: warn on HIGH, halt on CRITICAL.

strict() classmethod

Strict policy: halt on HIGH, block ungrounded output, block fabrications.

permissive() classmethod

Permissive policy: halt only on CRITICAL.

grounded(threshold=0.6) classmethod

Policy requiring the given grounding confidence threshold.

block(*capability_ids)

Add capability ids to the blocklist.

allow_only(*capability_ids)

Restrict selection to only these capability ids.

domain(*domains)

Require selected capabilities to declare at least one of these domains.

residency(region)

Require capabilities to match this data residency region.

safety(*classes)

Block capabilities with these safety classes.

clarify(threshold)

Set the ambiguity threshold at which the agent asks rather than guesses.

to_policy_context()

Compile this ergonomic policy into a TCF pre-filter.

to_safety_overrides()

Return orchestrator/SDK safety overrides derived from this policy.

CompiledTool dataclass

A ToolSpec bound to a runtime implementation and TCF descriptor.

ResultEnvelope dataclass

Structured result of executing one tool (SPEC-059 §3.4).

ToolIntent dataclass

A resolved intent to call a single tool with validated arguments (SPEC-059 §3.3).

ToolSpec dataclass

Developer-facing declaration of one tool the agent may use (SPEC-059 §3.1).

compile_tool(source, operation_types=None, kind=CapabilityKind.TOOL)

Compile an arbitrary tool source into a CompiledTool.

Accepts
  • Python callable (signature → schema)
  • :class:ToolSpec
  • dict with keys capability_id, input_schema, output_schema
  • :class:CapabilityDescriptor (passed through)

compile_tools(tools, operation_types=None)

Compile a mixed list of tool sources.

agent_sdk.agent

crp.agent_sdk.agent

Declarative Agent SDK surface (CRP-SPEC-059 §2).

crp.Agent is the steering wheel: declare tools + policy + model once and write zero loop code. The Agent builds the Tool Capability Fabric and executes through the positioned loop, emitting a transparency event stream.

AgentResponse dataclass

Result of one agent run.

answer property

Human-readable answer text.

sources property

Tool observations surfaced as sources.

decisions property

Decisions recorded in the CSO.

how_it_was_built property

Short narrative of the operation sequence.

open_questions property

Open questions carried forward in the CSO.

complete property

True when the run finished without halting and the plan was integrated.

Agent

Declarative agent: tools + policy + model (SPEC-059 §2).

Example::

import crp

def get_weather(city: str) -> dict:
    return {"city": city, "temp": 22}

agent = crp.Agent(model="local/llama3.1", tools=[get_weather])
result = agent.run("What's the weather in Sydney?")
print(result.answer)

register_tool(tool)

Register an additional tool and return self for chaining.

run(user_request, **kwargs)

Run the agent on user_request and return the full response.

ask(question, **kwargs)

Alias for :meth:run optimized for question-answering.

run_stream(user_request, **kwargs)

Run the agent and yield each transparency event as it occurs.

The model calls run in a background thread so events can be consumed incrementally.

run_tel(user_request, **kwargs)

Run the agent and yield AG-UI-compatible transparency events.

This is the public transparency stream consumed by frontends, CLIs, and audit consumers. It wraps :meth:_run in a background thread, maps internal :class:AgentEvent objects to AG-UI events, and adds CRP governance events (quality, provenance, state snapshot).

agent_sdk.events

crp.agent_sdk.events

Agent-side event vocabulary emitted by crp.Agent (CRP-SPEC-056 §4).

These events are the raw material for the Transparency Emission Layer. They are lean, serialisable, and provider-agnostic.

AgentEventKind

Bases: str, Enum

Canonical agent lifecycle events (SPEC-056 §4.1).

AgentEvent dataclass

A single event in the agent run stream.

to_dict()

Render as a JSON-serialisable dict.

agent_sdk.intent_compiler

crp.agent_sdk.intent_compiler

Intent compiler - turn Python callables / schemas into ToolSpecs (CRP-SPEC-059 §3.2).

The compiler is the bridge between the ergonomic SDK surface and the protocol's TCF. It extracts the tool's intent from its signature, docstring, and type hints.

compile_tool(source, operation_types=None, kind=CapabilityKind.TOOL)

Compile an arbitrary tool source into a CompiledTool.

Accepts
  • Python callable (signature → schema)
  • :class:ToolSpec
  • dict with keys capability_id, input_schema, output_schema
  • :class:CapabilityDescriptor (passed through)

compile_tools(tools, operation_types=None)

Compile a mixed list of tool sources.

agent_sdk.model_call

crp.agent_sdk.model_call

Provider-agnostic model-call adapter for the Agent SDK (CRP-SPEC-059 §5).

Reuses the existing positioned-loop adapter so that any CRP LLMProvider can power an Agent.

build_model_call(provider, *, temperature=0.2, max_tokens=1024)

Return a model_call callable bound to provider.

agent_sdk.policy

crp.agent_sdk.policy

First-class policy builder for crp.Agent (CRP-SPEC-059 §4).

Policy is the ergonomic surface; it compiles into the TCF's PolicyContext and optional orchestrator safety overrides.

Policy dataclass

Declarative safety/policy constraints for an agent run.

balanced() classmethod

Balanced policy: warn on HIGH, halt on CRITICAL.

strict() classmethod

Strict policy: halt on HIGH, block ungrounded output, block fabrications.

permissive() classmethod

Permissive policy: halt only on CRITICAL.

grounded(threshold=0.6) classmethod

Policy requiring the given grounding confidence threshold.

block(*capability_ids)

Add capability ids to the blocklist.

allow_only(*capability_ids)

Restrict selection to only these capability ids.

domain(*domains)

Require selected capabilities to declare at least one of these domains.

residency(region)

Require capabilities to match this data residency region.

safety(*classes)

Block capabilities with these safety classes.

clarify(threshold)

Set the ambiguity threshold at which the agent asks rather than guesses.

to_policy_context()

Compile this ergonomic policy into a TCF pre-filter.

to_safety_overrides()

Return orchestrator/SDK safety overrides derived from this policy.

agent_sdk.tool_manifest

crp.agent_sdk.tool_manifest

Typed tool manifest, intent compiler, and result envelope (CRP-SPEC-059 §3).

A :class:ToolSpec is the developer-facing declaration of a capability. It is agnostic of the underlying runtime - the same spec can drive a local Python callable, an MCP tool, or a remote service. The :class:IntentCompiler turns a ToolSpec into a TCF :class:CapabilityDescriptor so the protocol can select it without injecting the full catalogue into the model prompt.

ToolSpec dataclass

Developer-facing declaration of one tool the agent may use (SPEC-059 §3.1).

ToolIntent dataclass

A resolved intent to call a single tool with validated arguments (SPEC-059 §3.3).

CompiledTool dataclass

A ToolSpec bound to a runtime implementation and TCF descriptor.

ResultEnvelope dataclass

Structured result of executing one tool (SPEC-059 §3.4).