pydantic_acp API
This page documents the public surface re-exported by pydantic_acp.
Functions
create_acp_agent(agent=None, *, agent_factory=None, agent_source=None, config=None, projection_maps=None)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/runtime/server.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
create_acp_model(*, acp_agent=None, acp_command=None, model_name=None, cwd=None, env=None, stderr_mode='inherit', terminate_timeout=5.0, prompt_renderer=None, history_mode='latest_user', delegate_client=None, enable_pydantic_acp_meta=None, settings=None, profile=None)
Create a Pydantic AI model backed by an ACP agent or ACP stdio command.
Exactly one of acp_agent or acp_command must be provided. Passing
model_name=None leaves ACP model selection to the remote agent's session
default and does not send a session/set_config_option request for "model".
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/factory.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
run_acp(agent=None, *, agent_factory=None, agent_source=None, config=None, projection_maps=None)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/runtime/server.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
compose_projection_maps(projection_maps)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/projection.py
171 172 173 174 175 176 177 178 179 180 | |
Core Classes And Data Types
AdapterConfig(*, agent_name=DEFAULT_AGENT_NAME, agent_title=DEFAULT_AGENT_TITLE, agent_version=DEFAULT_AGENT_VERSION, allow_model_selection=False, approval_bridge=NativeApprovalBridge(), approval_state_provider=None, capability_bridges=list(), config_options_provider=None, enable_generic_tool_projection=True, enable_model_config_option=True, host_access_policy=None, hook_projection_map=HookProjectionMap(), models_provider=None, modes_provider=None, native_plan_additional_instructions=None, native_plan_persistence_provider=None, plan_id='acpkit.plan', plan_provider=None, plan_update_mode='full', prompt_capabilities=AdapterPromptCapabilities(), prompt_model_override_provider=None, replay_history_on_load=True, slash_command_provider=None, available_models=list(), session_store=MemorySessionStore(), output_serializer=DefaultOutputSerializer(), projection_maps=tuple(), tool_classifier=DefaultToolClassifier())
dataclass
AdapterModel(*, model_id, name, override, description=None)
dataclass
AdapterPromptCapabilities(*, audio=True, image=True, embedded_context=True)
dataclass
AcpSessionContext(*, session_id, cwd, created_at, updated_at, additional_directories=(), title=None, session_model_id=None, message_history_json=None, plan_markdown=None, plan_entries=list(), active_plan_id=None, config_values=dict(), mcp_servers=list(), metadata=dict(), transcript=list(), client=None, client_capabilities=None)
dataclass
supports_config_options()
Return whether the connected client accepts session config options.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/session/state.py
110 111 112 113 114 115 | |
supports_boolean_config_options()
Return whether the connected client accepts boolean config options.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/session/state.py
117 118 119 120 121 122 123 124 125 126 127 | |
supports_plan_content_updates()
Return whether the client supports unstable plan delta updates.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/session/state.py
129 130 131 132 | |
JsonValue = JsonPrimitive | list['JsonValue'] | dict[str, 'JsonValue']
module-attribute
RuntimeAgent = PydanticAgent[Any, Any]
module-attribute
ACP Client Provider Bridge
AcpProvider(*, acp_agent, host_client=None, cwd='.', name='acp', base_url='acp://local', protocol_version=PROTOCOL_VERSION, client_capabilities=None, client_info=None, mcp_servers=None, prompt_renderer=None, history_mode='latest_user', enable_pydantic_acp_meta=None)
Bases: Provider[Agent]
Pydantic AI provider that treats an ACP agent as the model backend.
This is the inverse of the normal pydantic-acp server adapter. The
server adapter exposes a pydantic_ai.Agent through ACP. AcpProvider
consumes an existing ACP agent and makes it available to Pydantic AI as a
provider/model pair, so application code can write ordinary Pydantic AI
agents while delegating the underlying model turn to ACP.
The provider owns ACP protocol/session setup, model selection through the
remote agent's model config option, host/client update
capture, and prompt rendering. It deliberately remains a provider rather
than an alternate agent framework: Pydantic AI still owns the outer agent
run, result validation, usage accumulation, and history shape.
Create a new ACP provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acp_agent
|
Agent
|
The ACP agent to wrap as a Pydantic AI provider/model. |
required |
host_client
|
Client | None
|
Optional upstream :class: |
None
|
cwd
|
str | Path
|
Working directory passed to the ACP session on creation. |
'.'
|
name
|
str
|
Provider name reported via :attr: |
'acp'
|
base_url
|
str
|
Base URL reported via :attr: |
'acp://local'
|
protocol_version
|
int
|
ACP protocol version used during
|
PROTOCOL_VERSION
|
client_capabilities
|
ClientCapabilities | None
|
ACP client capabilities sent during
|
None
|
client_info
|
Implementation | None
|
ACP implementation info sent during |
None
|
mcp_servers
|
Sequence[Any] | None
|
Optional list of MCP servers forwarded to
|
None
|
prompt_renderer
|
AcpPromptRenderer | None
|
Custom callable that converts Pydantic AI
messages into ACP prompt blocks. When |
None
|
history_mode
|
HistoryMode
|
Controls how previous messages are rendered into
the ACP prompt. |
'latest_user'
|
enable_pydantic_acp_meta
|
bool | None
|
Enables the private |
None
|
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
host
property
The ACP host bridge connected to the wrapped ACP agent.
updates
property
All ACP updates recorded by the host bridge so far.
enable_pydantic_acp_meta
property
Whether this provider opts into private pydantic_acp ACP metadata.
close()
async
Close the wrapped ACP agent when it exposes an async-compatible close hook.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
563 564 565 566 567 568 569 570 | |
model(model_name=None, *, settings=None, profile=None, history_mode=None)
Build an :class:AcpModel bound to this provider.
When model_name is None, the bridge does not call ACP
session/set_config_option for "model" and leaves model selection
to the wrapped agent's session default. The visible Pydantic AI model
name remains "agent".
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
render_prompt_blocks(messages, model_request_parameters, *, history_mode=None)
async
Render Pydantic AI model messages into ACP prompt blocks.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
request_prompt(*, model_name, prompt, model_request_parameters)
async
Send one prompt turn to the ACP agent and collect its visible text.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | |
AcpModel(model_name=None, *, provider, settings=None, profile=None, history_mode=None)
Bases: Model[Agent]
Pydantic AI Model backed by an ACP agent provider.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
AcpHostBridge(*, delegate=None)
Minimal ACP host/client implementation used by :class:AcpProvider.
ACP agents send their visible output to a connected ACP client via
session_update. Pydantic AI models, however, return a ModelResponse.
This bridge is the seam between the two contracts: it records ACP updates so
AcpModel can fold agent message chunks back into Pydantic AI response
parts, while optionally delegating real host operations to an upstream ACP
client supplied by the caller.
The bridge intentionally does not emulate a filesystem, terminal, approval UI, or extension namespace. When an ACP agent asks for such host operations and no delegate was supplied, the request fails explicitly instead of inventing host behavior that is not present.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
146 147 148 | |
snapshot_index()
Return an index that can later be used to read only new updates.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
150 151 152 | |
records_since(index, *, session_id=None)
Return recorded updates after index, optionally scoped to a session.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
154 155 156 157 158 159 160 161 162 163 164 | |
agent_message_text_since(index, *, session_id)
Concatenate ACP agent message chunks recorded after index.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
166 167 168 169 170 171 172 173 174 175 176 177 | |
usage_update_since(index, *, session_id)
Collect the latest ACP usage update observed after index.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
179 180 181 182 183 184 185 186 187 | |
session_update(session_id, update, **kwargs)
async
Record an ACP update and optionally forward it to a real host client.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
on_connect(conn)
Forward reverse connections to a delegate host client when it supports them.
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/client.py
359 360 361 362 | |
Agent Source Classes And Protocols
AgentFactory
Bases: Protocol[AgentFactoryDepsT, AgentFactoryOutputDataT]
AgentSource
Bases: Protocol[AgentDepsT, OutputDataT]
StaticAgentSource(agent, deps=None)
dataclass
Bases: Generic[AgentDepsT, OutputDataT]
FactoryAgentSource(factory)
dataclass
Bases: Generic[AgentDepsT, OutputDataT]
Session Store Classes
SessionStore
Bases: Protocol
MemorySessionStore(_sessions=dict())
dataclass
FileSessionStore(root)
dataclass
Provider State Classes And Protocols
ModelSelectionState(*, available_models, current_model_id, allow_any_model_id=False, enable_config_option=True, config_option_name='Model', config_option_description='Session-local model override.')
dataclass
ModeState(*, modes, current_mode_id=None)
dataclass
SessionModelsProvider
Bases: Protocol
SessionModesProvider
Bases: Protocol
ConfigOptionsProvider
Bases: Protocol
PlanProvider
Bases: Protocol
NativePlanPersistenceProvider
Bases: Protocol
ApprovalStateProvider
Bases: Protocol
ApprovalPolicy = Literal['allow', 'reject']
module-attribute
ApprovalPolicyStore
Bases: Protocol
SessionMetadataApprovalPolicyStore(metadata_key='approval_policies')
dataclass
PermissionOptionSet(*, allow_once_name='Allow', reject_once_name='Deny', allow_always_name='Always Allow', reject_always_name='Always Deny')
dataclass
Bridge Classes
CapabilityBridge
BufferedCapabilityBridge()
dataclass
Bases: CapabilityBridge
PrepareToolsBridge(*, metadata_key='prepare_tools', default_mode_id, modes, mode_config_key='mode', plan_generation_config_id='plan_generation_type', plan_generation_config_name='Plan Generation', plan_generation_config_description='How plan mode records ACP plan state.', default_plan_generation_type='structured')
dataclass
Bases: BufferedCapabilityBridge, Generic[AgentDepsT]
PrepareToolsMode(*, id, name, prepare_func, description=None, plan_mode=False, plan_tools=False)
dataclass
Bases: Generic[AgentDepsT]
PrepareOutputToolsBridge(*, metadata_key='prepare_output_tools', default_mode_id, modes, mode_config_key='prepare_output_tools_mode')
dataclass
Bases: BufferedCapabilityBridge, Generic[AgentDepsT]
PrepareOutputToolsMode(*, id, name, prepare_func, description=None)
dataclass
Bases: Generic[AgentDepsT]
ThinkingBridge(*, config_id='thinking', config_name='Thinking Effort', config_description='Session-local thinking/reasoning effort.')
dataclass
Bases: CapabilityBridge
HookBridge(metadata_key='hooks', hide_all=False, record_event_stream=True, record_model_requests=True, record_node_lifecycle=True, record_deferred_tool_calls=True, record_output_processing=True, record_output_validation=True, record_prepare_output_tools=True, record_prepare_tools=True, record_run_lifecycle=True, record_tool_execution=True, record_tool_validation=True)
dataclass
Bases: BufferedCapabilityBridge
ExternalHookEventBridge(*, metadata_key='external_hooks', projection_map=HookProjectionMap(), emission_mode='paired')
dataclass
Bases: BufferedCapabilityBridge
EventEmissionMode = Literal['paired', 'start_only']
module-attribute
HistoryProcessorBridge(metadata_key='history_processors', processor_names=list())
dataclass
Bases: BufferedCapabilityBridge
ThreadExecutorBridge(*, executor, metadata_key='thread_executor')
dataclass
Bases: CapabilityBridge
ImageGenerationBridge(*, builtin=True, local=None, fallback_model=None, background=None, input_fidelity=None, moderation=None, output_compression=None, output_format=None, quality=None, size=None, aspect_ratio=None, tool_names=_DEFAULT_IMAGE_GENERATION_TOOL_NAMES, metadata_key='image_generation')
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
SetToolMetadataBridge(*, tools='all', metadata_key=None, **metadata)
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/bridges/capability_support.py
175 176 177 178 179 180 181 182 183 184 | |
IncludeToolReturnSchemasBridge(tools='all', metadata_key=None)
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
ToolsetBridge(*, toolset, metadata_key='toolset')
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
PrefixToolsBridge(*, wrapped, prefix, metadata_key='prefix_tools')
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
WebSearchBridge(*, builtin=True, local=None, search_context_size=None, user_location=None, blocked_domains=None, allowed_domains=None, max_uses=None, tool_names=_DEFAULT_WEB_SEARCH_TOOL_NAMES, metadata_key='web_search')
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
WebFetchBridge(*, builtin=True, local=None, allowed_domains=None, blocked_domains=None, max_uses=None, enable_citations=None, max_content_tokens=None, tool_names=_DEFAULT_WEB_FETCH_TOOL_NAMES, metadata_key='web_fetch')
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
McpCapabilityBridge(*, url, builtin=True, local=None, id=None, authorization_token=None, headers=None, allowed_tools=None, description=None, tool_name_prefixes=_DEFAULT_MCP_TOOL_NAME_PREFIXES, metadata_key='mcp_capability')
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
SessionMcpBridge(*, metadata_key='session_mcp', include_instructions=True, include_return_schema=None, cache_tools=True, cache_resources=True, cache_prompts=True, tool_error_behavior='retry', max_retries=None, allowed_tools=None, tool_name_prefixes=frozenset(), toolset_id_prefix='acp-session-mcp', advertise_http=True, advertise_sse=True)
dataclass
Bases: CapabilityBridge
Attach ACP client-provided MCP servers to the Pydantic AI agent run.
ACP clients may pass MCP server definitions during session/new, session/load,
session/fork, or session/resume. The adapter persists those definitions on
AcpSessionContext.mcp_servers; this bridge turns them into a Pydantic AI
MCPToolset capability for the active session.
OpenAICompactionBridge(*, message_count_threshold=None, trigger=None, instructions=None, metadata_key='openai_compaction')
dataclass
Bases: BufferedCapabilityBridge, Generic[AgentDepsT]
AnthropicCompactionBridge(*, token_threshold=150000, instructions=None, pause_after_compaction=False, metadata_key='anthropic_compaction')
dataclass
Bases: CapabilityBridge, Generic[AgentDepsT]
McpBridge(*, metadata_key='mcp', approval_policy_scope='tool', config_options=list(), servers=list(), tools=list())
dataclass
Bases: CapabilityBridge
McpServerDefinition(*, server_id, name, transport, url=None, description=None, tool_prefix=None)
dataclass
McpToolDefinition(*, tool_name, server_id, kind='execute')
dataclass
Hook Introspection Helpers
RegisteredHookInfo(*, event_id, hook_name, tool_filters)
dataclass
list_agent_hooks(agent)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/runtime/hook_introspection.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Projection Classes
FileSystemProjectionMap(*, write_tool_names=frozenset(), read_tool_names=frozenset(), bash_tool_names=frozenset(), search_tool_names=frozenset(), default_write_tool=None, default_read_tool=None, default_bash_tool=None, default_search_tool=None, path_arg=None, content_arg=None, old_text_arg=None, command_arg=None, terminal_id_arg=None, search_path_arg=None, search_pattern_arg=None, render_search_results_as_tree=False, hide_dot_directories_in_tree=True, tree_root_label=None)
dataclass
WebToolProjectionMap(*, search_tool_names=_DEFAULT_SEARCH_TOOL_NAMES, fetch_tool_names=_DEFAULT_FETCH_TOOL_NAMES)
dataclass
BuiltinToolProjectionMap(*, web_projection_map=WebToolProjectionMap(), image_generation_tool_names=_DEFAULT_IMAGE_GENERATION_TOOL_NAMES, mcp_tool_name_prefixes=_DEFAULT_MCP_TOOL_NAME_PREFIXES)
dataclass
CompositeProjectionMap(*, maps)
dataclass
ProjectionAwareToolClassifier(*, base_classifier, projection_maps)
dataclass
Approval Presentation
PermissionRequestContext(*, session, tool_call, raw_input, cwd, classifier, projection_map=None)
dataclass
PermissionToolCallBuilder
Bases: Protocol
DefaultPermissionToolCallBuilder(*, status='pending')
dataclass
NativeApprovalBridge(*, enable_persistent_choices=False, tool_call_builder=DefaultPermissionToolCallBuilder(), policy_store=SessionMetadataApprovalPolicyStore(), option_set=PermissionOptionSet())
dataclass
ProjectionAwareApprovalBridge
Bases: Protocol
supports_projection_aware_approval_bridge(value)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/approvals.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
Slash Commands
SlashCommandRequest(*, name, argument, raw_prompt, session, agent)
dataclass
SlashCommandResult(*, text=None, updates=(), stop_reason='end_turn', handled=True, refresh_session_surface=True)
dataclass
SlashCommandProvider
Bases: Protocol
StaticSlashCommand(*, command, handler)
dataclass
StaticSlashCommandProvider(*, commands)
dataclass
SlashCommandHandler = Callable[[SlashCommandRequest], SlashCommandResult | None | Awaitable[SlashCommandResult | None]]
module-attribute
Projection Helpers
truncate_text(text, *, limit, marker=DEFAULT_TEXT_TRUNCATION_MARKER)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/_projection_text.py
20 21 22 23 24 25 26 27 28 29 30 31 32 | |
truncate_lines(lines, *, max_lines, truncation_line='... [truncated]')
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/_projection_text.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
single_line_summary(text, *, limit)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/_projection_text.py
51 52 53 54 55 56 57 58 59 | |
format_code_block(text, *, language=None, limit=None)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/_projection_text.py
62 63 64 65 66 67 68 69 70 71 | |
format_diff_preview(path, old_text, new_text, *, context_lines=3, max_lines=40, include_path_header=True, include_diff_headers=False)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/_projection_text.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
format_terminal_status(*, exit_code, signal)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/_projection_text.py
107 108 109 110 111 112 113 114 115 116 117 118 | |
caution_for_path(path, *, session_cwd, workspace_root=None, access_policy=None)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/_projection_risk.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
caution_for_command(command, *, args=None, cwd=None, session_cwd, workspace_root=None, access_policy=None)
Source code in packages/adapters/pydantic-acp/src/pydantic_acp/_projection_risk.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |