Python host and graph APIs
This page covers long-lived hosts and custom LangGraph assembly. To call an Agent from your application process, see the Python SDK reference.
Build a long-lived host (dataagent.host)
A host exposes Agents to other clients and manages listener settings, sessions, resource refresh, and logs in its own lifecycle.
Startup and extension refresh
| Name | Purpose |
|---|---|
server_listen(options=None) |
Read YAML server, expand variables using normal runtime precedence, and return (host, port). Default 127.0.0.1:8790 without a selected file. Raise on selected file load, expansion, or validation errors. Usable even if preparation fails |
ServerSettings |
Bind-address and port validation |
extension_revision(runtime) |
SHA-256 source fingerprint, excluding business inputs and session state |
refresh_extensions(runtime) |
Reread plugin, Hook, and MCP declarations into a new prepared runtime, keeping the model, paths, and startup policy. Swap after successful compilation. In-flight requests retain their graphs |
Logging, errors, and request identifiers
| Name | Purpose |
|---|---|
configure_logging(runtime=None) |
Configure backend.log, including early errors |
log_context |
Bind correlation fields via ContextVar and reset on exit |
log_event(...), safe_interrupt_fields(...) |
Structured logging and recursive feedback redaction |
register_log_secrets(values) |
Add redactions after extension or credential refresh and retain old ones |
diagnostic_traceback(error, secrets=()) |
Full sanitized stack for logs |
error_code(error) |
Map an exception to a fixed code |
ERROR_CODES |
Valid AG-UI error codes for safe errors and exception overrides |
opaque_id(value, label) |
Validate and return an ID |
OPAQUE_ID_PATTERN |
[A-Za-z0-9][A-Za-z0-9_-]{0,127} |
Sessions, graphs, and AG-UI adapters
create_agent(..., session=, input_workspaces=, extension_revision=). The defaultsessionmust be its normal path under the current Home and user. Withinput_workspaces=None, new sessions use YAML defaults and existing ones retain bindings. An explicit tuple, including(), must match the existing path order. Names are ignored for that comparison. The revision updates the Skill cache.runtime.paths.open_session(thread_id, *, create, output_dir=None, input_workspaces=None)registers or resumes, returning(SessionPaths, workspaces). A missing session withcreate=FalseyieldsNone. See directory rules.agent.as_agui(*, name="dataagent", **kwargs)creates an adapter whoserun(input)selects byinput.thread_id. Use a new adapter per request.agent.graph_for(thread_id)retrieves the native graph for an existing session, for example to callaget_state(config). A missing session raisesValueError.agent.graphcreates the default session on first access.
Standalone A2A server
Import these factories from dataagent.server.a2a. See the A2A reference for command-line usage.
| Name | Purpose |
|---|---|
create_a2a_server(runtime, *, host, port, auth_token=None, model=None, task_store=None, executor=None) |
Build a standalone Starlette app with replaceable model, TaskStore, or executor |
run_a2a_server(runtime, *, host, port, auth_token=None) |
Run it in uvicorn, as with dataagent serve-a2a |
Assemble a native LangGraph graph (dataagent.lowlevel)
build_graph opens one session and returns its native CompiledStateGraph. The caller passes context on invocation and owns the semantic client lifecycle. Use create_agent for thread routing and multiple cached graphs.
from dataagent import AgentContext, load_mcp_tools
from dataagent.lowlevel import build_graph
context = AgentContext(runtime, semantic_client=client)
graph = build_graph(
runtime,
context=context,
checkpointer=checkpointer,
mcp_tools=await load_mcp_tools(runtime),
)
result = await graph.ainvoke(inputs, config, context=context)build_graph(runtime, *, checkpointer=None, model=None, session=None,
input_workspaces=None, mcp_tools=None, extension_revision=None, context=None)- Without a session or context, use session
sdk. - Configured MCP requires
mcp_tools; configured semantics require the context's client. dataagent.entryselects only that compiled entry.- Pass additional LangChain callbacks in
config["callbacks"]orgraph.with_config(callbacks=[...]).
dataagent.lowlevel may change with LangGraph. See __all__ in dataagent, dataagent.host, and dataagent.lowlevel for exports.
Assemble human interaction manually
For explicit assembly, the caller supplies model, tools, subagents, and the checkpointer:
from pathlib import Path
from langgraph.checkpoint.memory import InMemorySaver
from dataagent import read_yaml
from dataagent.core.graph import create_deep_agent
from dataagent.extensions.hitl import HITLMiddleware
path = Path("/path/to/plugin/.plugin.yaml")
middleware = HITLMiddleware.from_config(read_yaml(path)["hitl"], root=path.parent, namespace="main")
graph = create_deep_agent(
model=model,
tools=tools,
subagents=subagents,
middleware=[middleware],
checkpointer=InMemorySaver(),
)Pass a system prompt separately when assembling explicitly. For recovery after a process restart, replace the in-memory saver with a persistent checkpointer and keep the same thread and compatible policies. See execution and recovery.