Local Architecture Practice: Putting an Agent Team Inside a Chat App

    This article describes a local architecture that presents agents as chat contacts, separates the UI from execution management, unifies protocol events, and covers logging, multi-agent isolation, permissions, config migration, and acceptance checks for a controllable agent workbench.

    From Chat Entry Point to Agent Workbench

    Traditional assistants are usually organized around a single conversation window: the user asks a question, the system answers, and tools are invoked when needed. When agents take on code changes, research, file handling, and task execution, a single chat entry starts to break down. Context from different tasks mixes together, execution permissions are hard to separate, and long-running work is difficult to track.

    A better fit for multi-role collaboration is to present agents as contacts in a chat app. Each contact is an execution unit with its own configuration, session state, and tool permissions. Users can assign tasks separately and inspect each agent’s run.

    The point is not avatars and a contact list. It is turning agents from “features inside a conversation” into managed task runners. The UI expresses roles, messages, and status. The runtime starts processes, connects tools, persists context, and enforces safety constraints.

    A contact does not automatically mean a separate machine. Multiple agents can share one host, or use different working directories and isolation. Real isolation depends on process privileges, file access, and the runtime—not on UI roles alone.

    Overall Architecture: Separate UI from Execution Management

    A workbench like this can use two main processes: one for the chat UI and one for local execution management. Agents still run as CLI processes, scheduled by the execution service.

    The flow is:

    User action → chat UI → local execution management service → protocol adapter → agent CLI process → files and apps within the granted scope

    Execution events flow back to the UI and are also written to durable logs.

    1. UI layer: show state, do not hold execution privileges

    The UI manages the contact list, conversation views, task status, permission prompts, and errors. It should not assemble shell commands, and it should not scatter executable paths, environment variables, or credential handling through UI code.

    This split has two benefits: UI failures do not rewrite process-management rules, and permission checks and parameter validation can live in one place instead of differing by screen.

    2. Local execution layer: unified lifecycle management

    The execution service starts, stops, restarts, and reaps agent processes, and keeps the mapping between sessions and processes. It also forwards input, parses output, handles timeouts, records exit codes, and recovers from failures.

    Task status should not be only “running” and “done.” At minimum, distinguish queued, starting, running, waiting for approval, cancelled, and failed. Implementations can simplify the set, but process existence is not the same as healthy progress.

    3. Local listening: smaller attack surface, not a full security boundary

    The execution service can bind to loopback so it is not open to the LAN or the public internet. That reduces remote access risk, but you still need to guard against other processes on the same machine and requests from malicious pages.

    The local service should still validate request origin, use session-level access tokens, and restrict cross-origin access. State-changing operations need request validation. Port numbers are deployment parameters; support conflict detection and configuration instead of treating a fixed port as a correctness assumption.

    Protocol Normalization: One Event Model for the UI

    CLI agents use different protocols: line-oriented structured output, request/response, or dedicated agent protocols. If the UI absorbs those differences, each new backend forces large UI changes.

    A more durable approach is adapters in the execution layer that map external protocols to a unified internal event model.

    At least distinguish:

    • Text deltas: incremental generation
    • Tool-call requests: intended operations
    • Tool results: returns or errors
    • Permission requests: actions that need user approval
    • Task state changes: lifecycle
    • Process exit or faults: diagnostics

    Events need more than type and payload. For concurrency, reconnect, and log replay, include session id, task id, sequence number, and timestamps.

    Illustrative internal event (not a product API):

    1. {
    2. "type": "task_state",
    3. "agent_id": "role_a",
    4. "thread_id": "thread_01",
    5. "task_id": "task_03",
    6. "sequence": 18,
    7. "state": "waiting_approval"
    8. }

    Unify shared semantics while preserving real differences. If one backend can resume history and another can only start a new process, do not claim identical capabilities for UI consistency.

    Event Streams and Logs: Observable and Recoverable

    The workbench must show execution in near real time. For server-to-UI push, server-sent events are a fit; submit, cancel, and approve go as separate requests.

    One connection can carry events for many sessions. The client must route by session id, not by whichever chat is currently open.

    1. Reconnect needs an explicit consistency policy

    Even on localhost, connections drop on UI refresh, process restart, or resource pressure. If the server can replay by sequence number, the client can fill gaps after reconnect and dedupe by unique ids.

    Without replay, say clearly that the display may have gaps and provide a log query path. Streaming does not guarantee completeness, and it does not guarantee a task runs only once.

    2. Persist structured logs per session

    Append structured events line by line for ordering, diagnosis, and session restore. Keep normalized event logs separate from raw process output: the former for UI rebuild and audit, the latter for protocol debugging.

    Apply size limits, retention, and redaction. Long jobs produce large tool output; storing everything increases storage cost and can leak credentials or sensitive file content.

    3. Separate narrative messages from execution facts

    “About to modify a file” does not mean the file changed. A natural-language “task complete” does not replace process exit status and tool results. Show explanatory text separately from evidence so users do not misread outcomes.

    Multi-Agent Management: Role Config Is Not Autonomous Collaboration

    A contact-style UI helps organize work, but several agents at once does not mean they collaborate reliably. Collaboration still needs task split, handoff, conflict handling, and acceptance.

    1. Independent working boundaries per role

    Role config can include duty description, execution backend, working directory, tools, memory scope, and permission requirements. Distinguish current-session context, long-term preferences, and project materials so unconfirmed scratch content does not linger.

    When several agents touch the same project, prefer separate working directories or explicit file locking. Otherwise one task may rewrite a file another is still analyzing.

    2. Avoid duplicate execution and overwrite

    Writes to the same resource need conflict detection or serialization. Retries need care: file writes, notifications, and remote submits can have side effects again.

    A practical approach is stable task ids, records of completed critical operations, and a state check before rerun. Whether retry is safe still depends on whether tools are idempotent.

    3. Local degradation when a backend is unavailable

    If a CLI is missing, login is invalid, or protocol parse fails, mark that role unavailable instead of taking down the whole workbench.

    Availability checks should be layered: binary present, can start, auth valid, required capabilities met. Errors should name the failing stage, not a generic “connection failed.”

    Permissions and Credentials: Default Off Beats After-the-Fact Warnings

    Local execution reduces some data hops; it does not mean data never leaves the device. If the agent calls a remote model, prompts, code snippets, or file content may still go to an external service. Spell out data boundaries for the UI, execution process, model service, and connected tools.

    External app connections should default off. Scheduled jobs and auto-routines should default paused. After importing config, confirm each grant instead of executing immediately.

    High-risk actions—deleting files, installing dependencies, running scripts, changing remote data—should get extra confirmation. Narrow grants to needed directories, operation types, and time windows so one approval does not become unlimited access.

    Do not store credentials in team config, ordinary session logs, or shareable files. Use OS secret storage, and keep secrets out of error messages, debug output, and child-process environments.

    Team Config Migration: Share Structure, Not Permissions

    Save team definitions as structured text for readability, versioning, and migration. The file can describe roles, backend requirements, connection declarations, and routines, but must exclude tokens, auth sessions, and other secrets.

    Treat import as untrusted input: check size, field types, path scope, and version compatibility. Do not run a command just because the file names it.

    A safer import flow:

    1. Parse and display roles, connections, and automatic tasks.
    2. Validate local runtime and config compatibility.
    3. Keep connections closed and routines paused.
    4. Let the user pick a working directory and complete authorization.
    5. Run a limited-privilege trial before enabling the full flow.

    The team file is a config template, not a copy of another machine’s privileges.

    Delivery and Acceptance: Controllable Execution First, Then Scale the Team

    Early on, complete one agent end to end: submit, receive events, show status, cancel, persist logs. Then add a second protocol to verify the adapter isolates backends. Only then expand concurrent tasks, config migration, and app connections.

    Acceptance should cover more than “can we chat”:

    • After a child process dies unexpectedly, does the UI show accurate status?
    • After cancel, are the child and its descendants cleaned up?
    • After an event stream drop, can you recover or explain the gap?
    • When two tasks edit the same file, is there conflict protection?
    • After import, do external connections stay off until authorized?
    • Do logs and exports contain secrets?
    • If one backend is down, do other tasks still run?

    Putting an agent team in a chat app is really a readable control surface over a local execution system. Reliability comes from protocol boundaries, lifecycle management, event consistency, resource isolation, and authorization. When those are explicit, the contact list becomes a workbench that is traceable, controllable, and portable.