Skip to content

langchain_acp API

This page documents the public surface re-exported by langchain_acp.

Functions

create_acp_agent(graph=None, *, graph_factory=None, graph_source=None, config=None, event_projection_maps=None, projection_maps=None)

Source code in packages/adapters/langchain-acp/src/langchain_acp/runtime/server.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def create_acp_agent(
    graph: Any | None = None,
    *,
    graph_factory: GraphFactory | None = None,
    graph_source: GraphSource | None = None,
    config: AdapterConfig | None = None,
    event_projection_maps: list[EventProjectionMap] | None = None,
    projection_maps: list[ProjectionMap] | None = None,
) -> AcpAgent:
    resolved_source = _resolve_graph_source(
        graph=graph,
        graph_factory=graph_factory,
        graph_source=graph_source,
    )
    resolved_config = _resolve_config(
        config=config,
        event_projection_maps=event_projection_maps,
        graph_name=getattr(graph, "name", None),
        projection_maps=projection_maps,
    )
    return LangChainAcpAgent(resolved_source, config=resolved_config)

run_acp(graph=None, *, graph_factory=None, graph_source=None, config=None, event_projection_maps=None, projection_maps=None)

Source code in packages/adapters/langchain-acp/src/langchain_acp/runtime/server.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def run_acp(
    graph: Any | None = None,
    *,
    graph_factory: GraphFactory | None = None,
    graph_source: GraphSource | None = None,
    config: AdapterConfig | None = None,
    event_projection_maps: list[EventProjectionMap] | None = None,
    projection_maps: list[ProjectionMap] | None = None,
) -> None:
    adapter = create_acp_agent(
        graph=graph,
        graph_factory=graph_factory,
        graph_source=graph_source,
        config=config,
        event_projection_maps=event_projection_maps,
        projection_maps=projection_maps,
    )
    asyncio.run(run_agent(adapter))

compose_projection_maps(projection_maps)

Source code in packages/adapters/langchain-acp/src/langchain_acp/projection.py
210
211
212
213
214
215
216
217
218
219
def compose_projection_maps(
    projection_maps: Sequence[ProjectionMap] | None,
) -> ProjectionMap | None:
    if projection_maps is None:
        return None
    if len(projection_maps) == 0:
        return None
    if len(projection_maps) == 1:
        return projection_maps[0]
    return CompositeProjectionMap(maps=tuple(projection_maps))

compose_event_projection_maps(projection_maps)

Source code in packages/adapters/langchain-acp/src/langchain_acp/event_projection.py
53
54
55
56
57
58
59
60
61
62
def compose_event_projection_maps(
    projection_maps: Sequence[EventProjectionMap] | None,
) -> EventProjectionMap | None:
    if projection_maps is None:
        return None
    if len(projection_maps) == 0:
        return None
    if len(projection_maps) == 1:
        return projection_maps[0]
    return CompositeEventProjectionMap(maps=tuple(projection_maps))

Core Classes And Data Types

AdapterConfig(*, agent_name=DEFAULT_AGENT_NAME, agent_title=DEFAULT_AGENT_TITLE, agent_version=DEFAULT_AGENT_VERSION, approval_bridge=NativeApprovalBridge(), available_models=list(), available_modes=list(), capability_bridges=tuple(), config_options_provider=None, default_model_id=None, default_mode_id=None, default_plan_generation_type='structured', enable_plan_progress_tools=False, event_projection_maps=tuple(), models_provider=None, modes_provider=None, native_plan_additional_instructions=None, native_plan_persistence_provider=None, output_serializer=DefaultOutputSerializer(), plan_mode_id=None, plan_provider=None, projection_maps=tuple(), prompt_capabilities=AdapterPromptCapabilities(), replay_history_on_load=True, slash_command_provider=None, session_store=MemorySessionStore(), tool_classifier=DefaultToolClassifier()) dataclass

AcpSessionContext(*, session_id, cwd, created_at, updated_at, title=None, session_model_id=None, session_mode_id=None, plan_entries=list(), plan_markdown=None, config_values=dict(), mcp_servers=list(), metadata=dict(), transcript=list(), client=None) dataclass

JsonValue = JsonPrimitive | list['JsonValue'] | dict[str, 'JsonValue'] module-attribute

TaskPlan

Bases: BaseModel

Graph Source Classes And Protocols

CompiledAgentGraph = CompiledStateGraph[Any, Any, Any, Any] module-attribute

GraphFactory

Bases: Protocol

GraphSource

Bases: Protocol

StaticGraphSource(graph) dataclass

FactoryGraphSource(factory) dataclass

Session Store Classes

SessionStore

Bases: Protocol

MemorySessionStore(_sessions=dict()) dataclass

FileSessionStore(root) dataclass

Provider State Classes And Protocols

ConfigOption = SessionConfigOptionSelect | SessionConfigOptionBoolean module-attribute

ConfigOptionsProvider

Bases: Protocol

ModelSelectionState(*, available_models, current_model_id, allow_any_model_id=False, enable_config_option=True, config_option_name='Model') dataclass

ModeState(*, modes, current_mode_id=None, enable_config_option=True, config_option_name='Mode') dataclass

NativePlanPersistenceProvider

Bases: Protocol

PlanProvider

Bases: Protocol

SessionModelsProvider

Bases: Protocol

SessionModesProvider

Bases: Protocol

Bridge Classes

CapabilityBridge

BufferedCapabilityBridge() dataclass

ConfigOptionsBridge(*, provider) dataclass

ModelSelectionBridge(*, available_models=(), default_model_id=None, provider=None) dataclass

ModeSelectionBridge(*, available_modes=(), default_mode_id=None, provider=None) dataclass

ToolSurfaceBridge(*, tool_kinds=dict(), approval_policy_keys=dict()) dataclass

DeepAgentsCompatibilityBridge(*, metadata_key='deepagents') dataclass

GraphBridgeBuilder(*, base_classifier, bridges) dataclass

GraphBuildContributions(*, interrupt_configuration=dict(), metadata=dict(), middleware=(), response_format=None, system_prompt_parts=(), tools=()) dataclass

Plan Helpers

NativePlanGeneration = TaskPlan module-attribute

PlanGenerationType = Literal['tools', 'structured'] module-attribute

acp_get_plan()

Return the saved plan and numbered entries.

Source code in packages/adapters/langchain-acp/src/langchain_acp/plan.py
89
90
91
92
93
94
def acp_get_plan() -> str:
    """Return the saved plan and numbered entries."""
    context = _active_plan_context()
    if context is None:
        return "No active ACP session is bound."
    return context.runtime.format_native_plan(context.session)

acp_mark_plan_done(index) async

Mark a single plan entry completed by its 1-based index.

Source code in packages/adapters/langchain-acp/src/langchain_acp/plan.py
133
134
135
136
137
138
139
140
141
142
143
async def acp_mark_plan_done(index: int) -> str:
    """Mark a single plan entry completed by its 1-based index."""
    context = _active_plan_context()
    if context is None:
        return "No active ACP session is bound."
    updated_entry = await context.runtime.update_native_plan_entry(
        context.session,
        index=index,
        status="completed",
    )
    return f"Marked plan entry {index} as completed: {updated_entry.content}"

acp_set_plan(entries, plan_md=None) async

Replace the current ACP-owned plan state.

Source code in packages/adapters/langchain-acp/src/langchain_acp/plan.py
 97
 98
 99
100
101
102
103
104
105
106
107
async def acp_set_plan(entries: list[PlanEntry], plan_md: str | None = None) -> str:
    """Replace the current ACP-owned plan state."""
    context = _active_plan_context()
    if context is None:
        return "No active ACP session is bound."
    await context.runtime.persist_native_plan_state(
        context.session,
        entries=entries,
        plan_markdown=plan_md,
    )
    return f"Recorded {len(entries)} plan entries."

acp_update_plan_entry(index, status=None, content=None, priority=None) async

Update a single plan entry by its 1-based index.

Source code in packages/adapters/langchain-acp/src/langchain_acp/plan.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
async def acp_update_plan_entry(
    index: int,
    status: str | None = None,
    content: str | None = None,
    priority: str | None = None,
) -> str:
    """Update a single plan entry by its 1-based index."""
    context = _active_plan_context()
    if context is None:
        return "No active ACP session is bound."
    updated_entry = await context.runtime.update_native_plan_entry(
        context.session,
        index=index,
        status=status,
        content=content,
        priority=priority,
    )
    return (
        f"Updated plan entry {index}: "
        f"[{updated_entry.status}] ({updated_entry.priority}) {updated_entry.content}"
    )

native_plan_tools()

Source code in packages/adapters/langchain-acp/src/langchain_acp/plan.py
146
147
148
149
150
151
152
def native_plan_tools() -> tuple[object, ...]:
    return (
        acp_get_plan,
        acp_set_plan,
        acp_update_plan_entry,
        acp_mark_plan_done,
    )

Projection Classes

FileSystemProjectionMap(*, write_tool_names=frozenset(), read_tool_names=frozenset(), search_tool_names=frozenset(), execute_tool_names=frozenset(), default_search_tool=None, search_path_arg='path', search_pattern_arg='pattern', render_search_results_as_tree=False, hide_dot_directories_in_tree=False, tree_root_label='.') dataclass

DeepAgentsProjectionMap(*, base=(lambda: FileSystemProjectionMap(read_tool_names=(frozenset({'read_file'})), write_tool_names=(frozenset({'edit_file', 'write_file'})), search_tool_names=(frozenset({'glob', 'grep', 'ls'})), execute_tool_names=(frozenset({'execute'}))))()) dataclass

CompositeProjectionMap(*, maps) dataclass

StructuredEventProjectionMap(*, event_keys=_EVENT_KEYS) dataclass

CompositeEventProjectionMap(*, maps) dataclass

Projection Helpers

build_tool_start_update(*, tool_call_id, tool_name, classifier, raw_input, cwd, projection_map)

Source code in packages/adapters/langchain-acp/src/langchain_acp/projection.py
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
def build_tool_start_update(
    *,
    tool_call_id: str,
    tool_name: str,
    classifier: ToolClassifier,
    raw_input: Any,
    cwd: Path | None,
    projection_map: ProjectionMap | None,
) -> ToolCallStart:
    projected = (
        projection_map.project_start(tool_name, cwd=cwd, raw_input=raw_input)
        if projection_map
        else None
    )
    return ToolCallStart(
        session_update="tool_call",
        tool_call_id=tool_call_id,
        title=(projected.title if projected is not None else None) or tool_name,
        kind=classifier.classify(tool_name, raw_input),
        locations=(
            projected.locations
            if projected is not None and projected.locations is not None
            else None
        )
        or extract_tool_call_locations(raw_input)
        or None,
        raw_input=raw_input,
        status=(projected.status if projected is not None else None) or "in_progress",
        content=projected.content if projected is not None else None,
    )

build_tool_progress_update(*, tool_call_id, tool_name, classifier, raw_input, raw_output, serialized_output, cwd, projection_map, status)

Source code in packages/adapters/langchain-acp/src/langchain_acp/projection.py
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
def build_tool_progress_update(
    *,
    tool_call_id: str,
    tool_name: str,
    classifier: ToolClassifier,
    raw_input: Any,
    raw_output: Any,
    serialized_output: str,
    cwd: Path | None,
    projection_map: ProjectionMap | None,
    status: ToolCallStatus,
) -> ToolCallProgress:
    projected = (
        projection_map.project_progress(
            tool_name,
            cwd=cwd,
            raw_input=raw_input,
            raw_output=raw_output,
            serialized_output=serialized_output,
            status=status,
        )
        if projection_map
        else None
    )
    return ToolCallProgress(
        session_update="tool_call_update",
        tool_call_id=tool_call_id,
        title=projected.title if projected is not None else None,
        kind=classifier.classify(tool_name, raw_input),
        locations=(
            projected.locations
            if projected is not None and projected.locations is not None
            else None
        )
        or extract_tool_call_locations(raw_input)
        or None,
        raw_input=raw_input,
        raw_output=raw_output,
        status=(projected.status if projected is not None else None) or status,
        content=(
            projected.content
            if projected is not None and projected.content is not None
            else (
                [ContentToolCallContent(type="content", content=_text_block(serialized_output))]
                if serialized_output
                else None
            )
        ),
    )

extract_tool_call_locations(raw_input)

Source code in packages/adapters/langchain-acp/src/langchain_acp/projection.py
1031
1032
1033
1034
1035
1036
1037
def extract_tool_call_locations(raw_input: Any) -> list[ToolCallLocation]:
    if not _is_string_keyed_object_dict(raw_input):
        return []
    path = _first_string(raw_input, _PATH_KEYS)
    if path is None:
        return []
    return [ToolCallLocation(path=path)]