Backend and ADK architecture
Understand the FastAPI route layer and ADK execution modules behind Pinter.
The backend uses FastAPI, SQLAlchemy, PostgreSQL, and Google ADK.
The active API surface is mounted under:
/api
Route registration lives in:
pinter-be/routes/api.py
Main backend modules
| Module | Path | Responsibility |
|---|---|---|
| Routes | routes/api.py | Composes the eight canonical domain routers below /api. |
| Agent executor | modules/agents/runtime/executor.py | Coordinates factory, runner, persistence, prompt guard, and SSE output. |
| Agent factory | modules/agents/runtime/factory/agent_builder.py | Builds ADK agents from DB config. |
| Tool registry | modules/agents/runtime/tool_registry.py | Resolves tool references to ADK-compatible tools. |
| Workflow executor | modules/agents/runtime/ADKWorkflowExecutor.py | Runs graph workflows with validation, planning, node execution, and state. |
| Workflow compiler | modules/agents/runtime/workflow/compiler.py | Converts graph data into an execution plan. |
| Session config | modules/agents/runtime/session_config.py | Configures ADK session service. |
| Evaluation | modules/agents/runtime/evaluation.py | Runs evaluation sets and stores results. |
Agent run flow
ADKExecutor.execute() is the main runtime interface for chat-driven agent execution.
It performs these steps:
- Validate attachments
Multimodal inputs are checked before model execution.
- Gemini Direct Document Bypass: If the agent runs on a Google Gemini provider model, PDF attachments bypass the traditional text-extraction/OCR pipeline and are passed directly as native multimodal document parts. This preserves layout, charts, formulas, and visual context.
- Non-Gemini Providers: Standard OCR and plain text extraction pipelines are applied before passing text into the prompt.
- Guard the prompt
Prompt extraction and prompt injection attempts are blocked before agent creation:
- System One / JEV Guardrail Middleware: Analyzes incoming prompts for jailbreak attempts, delimiter hijacking, and prompt extraction patterns.
- PII Redaction: Sensitive personal data patterns are automatically redacted based on the platform’s security policy.
- Defense Modes: Configurable agent defense modes evaluate strictness of boundaries before delegating to the model.
- Build the agent
AgentFactoryloads the agent, model, tools, planner, and generation config. - Run the agent
AgentRunnerstreams events back to the client. - Persist the run
Messages, token usage, and traces are saved after execution completes.
Agent construction
AgentFactory.create_agent(agent_id) loads an agent record and creates the correct ADK agent type.
| Agent type | Implementation |
|---|---|
| Standard LLM agent | LlmAgent |
| Sequential workflow | SequentialAgent |
| Parallel workflow | ParallelAgent |
| Loop workflow | LoopAgent |
| Conditional workflow | ConditionalAgent |
| Human-in-the-loop workflow | HumanInTheLoopAgent |
Runtime tool confirmation (HITL gate)
In addition to workflow-level HumanInTheLoopAgent, Pinter implements interactive, tool-call-level confirmation directly on standard agents.
When building an agent, AgentFactory installs approval_gate as the first callback in the before_tool_callback chain:
"before_tool_callback": [approval_gate, rehydrate_tool_args]
- Gate evaluation: When a model calls a mutative or external tool (a tool whose name starts with
create_,update_,delete_,run_, oradd_, or a non-read-onlyquery_snowflakecall; MCP tools are judged by name like any other tool),approval_gatecallstool_context.request_confirmation(hint=...)and setstool_context.actions.skip_summarization = True. The gate is skipped when the session state key_approval_modeisfull-accessand no confirmation answer exists yet.AgentRunner.runwrites that key throughstate_deltaon every turn from the request’sapproval_mode, defaulting tofull-accesswhen omitted. - Turn suspension: The ADK run halts immediately without invoking the model to summarize or explain prematurely. An
approval_requiredSSE event is emitted to the client. - Turn resumption: Upon user approval or rejection,
POST /api/conversations/{id}/approvals/{approvalId}submits aFunctionResponsematching the confirmation call. Parallel pending confirmations are resumed together: the optionaldecisionslist adds oneFunctionResponseper extra approval to the sameContent, so the model does not continue while others are still pending. An existing answer always wins over the mode, so a rejection is enforced even infull-access. The executor updates the assistant turn in-place and streams the execution result back to the user.
The factory also merges the 5-pattern instruction fields into a single instruction:
- Identity.
- Mission.
- Methodology.
- Boundaries.
- Examples.
Tool reference formats
The tools array on an agent can contain:
| Format | Meaning |
|---|---|
google_search | ADK Google Search built-in. |
code_execution | ADK code execution configuration. |
<uuid> | Tool row from tools. |
agent:<uuid> | Another agent wrapped as a tool. |
mcp:<uuid> | Legacy MCP tool config from tools. |
mcp_server:<uuid> | MCP server from mcp_servers. |
Workflow executor
ADKWorkflowExecutor.execute() runs graph workflows and returns JSON:
{
"status": "success",
"output": "Final response",
"history": [],
"total_token_usage": {},
"debug_state_keys": [],
"workflow_run_id": "uuid",
"node_runs": []
}
The workflow runtime validates the graph, compiles an execution plan, runs ready nodes, handles condition routing, prunes dead paths, and records node results.