TheFocus.AI Engineering handbook

§ 04 · Agent integration / Draft handbook/agent-services.md

Build an agent service

Find the integration state machines, their owners, and the checks between them.

Proposed guidance. Not ratified; respect the project's adopted policy and exceptions.Markdown .md · GitHub ↗

A2A carries conversations. MCP exposes tools, resources, and interactive Apps. Neither protocol decides who can access a client's data, which database to use, or who may approve a release. Record the adopted protocol version, local application profile, and policy choices separately.

Find the integration state machine

These nine state machines describe the Workbench integration with external specialists. They are separate lifecycles, not one shared status. A discovered card can coexist with a denied invocation; a disconnected stream can coexist with a running task. The linked tables own the transitions, guards, effects, failures, and recovery rules. State labels describe behavior, not necessarily literal database values or SDK enums.

State machineWho controls itQuestion the transition table answers
Discovery and readinessHost card fetcher and acceptance runnerDid discovery succeed, or did an authenticated invocation pass?
Registry and dispatchOperator, policy store, and dispatcherDoes the current revision still permit this target and identity?
Browser sessionClerk and host backendCan the host establish a human for a new grant?
Machine credential and tokenOperator, issuer, caller cache, and receiverCan the caller mint a token, and does the receiver accept it?
Human delegation and entitlementGrant issuer and receiving specialistIs the human bound to this sender and allowed this operation?
Bounded demo accessProvider operator and verifierDoes the separate, approved demo path still permit access?
A2A task and transportProvider task store and caller recovery codeIs the task finished, paused, or merely no longer observable?
MCP view and snapshotHost bridge, view store, and providerDoes the action restore a snapshot, call a tool, or update future-turn context?
Cutover and recoveryRelease owner and approved operatorCan this code, schema, and identity configuration receive traffic or roll back?

Read transitions without inventing guarantees

A transition needs an event, a guard that permits it, and an owner that applies its effects. A failed guard follows the stated failure path, not a weaker authorization profile. Recovery can be a supported read, reauthentication, configuration repair, or an operator decision; it is not automatically a retry.

Keep each statement's basis explicit:

  • Protocol requirements apply to the named version and supported operations.

  • Inspected behavior is bounded to the revisions in the source record, not a claim about today's deployment.

  • Selected policy states what this integration requires, including a human grant on every Workbench specialist call. Implementation acceptance remains separate.

  • Proposed gates, such as live-probe enablement, are not implemented guarantees or release approval.

Before changing a transition, name its guard and failure outcome in the change description. Exercise both an allowed transition and a rejected one using the owning page's acceptance checks. Record unsupported recovery operations and unverified deployment behavior instead of marking them passed. These tables are an operational description, not an exhaustive protocol model or a formal proof.

Put responsibility on the owning service

A specialist owns its model loop, guardrails, data, and persisted state. The host owns its registry, dispatch policy, and host-user session. They communicate through authenticated interfaces, not imports of another service's code or queries against its database.

Workbench uses registry-derived specialist calls and keeps credentials on the server. Its resident agent also uses the A2A relay; its repository forbids a private chat route. That is Workbench's application architecture, not an A2A requirement on every vendor.

Use one definition through the adapters

ConcernFocus defaultVerification
Tool shapeA name, description, input schema, and execution handler in one ToolSpecValidate public inputs at the boundary.
Tool catalogDerive model and MCP tool exposure from that definitionNo divergent second schema or handler.
RefusalStructured result with a stable reason, not an ambiguous successful stringTests distinguish denial from empty data and execution failure.
CitationStructured provenance tied to the returned resultSource identifiers survive every adapter.
System promptOne canonical prompt; generate or compare any runtime mirrorA changed prompt cannot leave the runtime on stale instructions.
PersistencePostgres task/session state with verified-owner scopingRestart, missing configuration, failed writes, and cross-owner reads are tested.
Model entry pointOne runAgent used by conversational adaptersAn MCP rendering action does not implicitly invoke the model.

The client's onboarding packet defines its own refusal/citation Parts and extensions. Use those types when adopting that contract; do not claim they are universal A2A fields. A vendor's framework, model, database, and cloud remain implementation choices.

Persist at the selected owner boundary

Derive the owner from verified identities, not request metadata. Workbench external specialists use the required human-delegation profile, including on coordinator-routed calls. The receiver authorizes the sender and human independently of task provenance. A machine-only profile is an option for explicitly approved nonhuman workloads outside that integration; it scopes data to the authorized service and does not segregate humans. Check context/task ownership on every operation. Do not rely on an SDK's default anonymous owner to isolate callers.

Await required writes before terminal success, or use an explicitly supported durable completion mechanism. Do not silently fire and forget persistence. Production fails closed without its database; in-memory state is an explicit mock mode. Apply migrations before traffic shifts, not on application boot.

Implement only the contract you advertise

Publish a card whose interfaces, versions, streaming, security, and extensions match the actual endpoint. A native Clerk bearer profile must not advertise an invented OAuth token endpoint. Use one handler for supported dialects, and make unsupported operations explicit rather than retrying through another dialect.

The server recipe gives the versioned layout and event ordering. Test task-before-update and artifact-before-terminal ordering only on task-producing paths; a standalone Message need not create a task.

The component lifecycle evidence covers local resource ownership behind these interfaces. It is not a protocol contract.