Skip to content

Rewire function_app.py; delete swarm_server.py + chat.py (PR 4/4)#4

Merged
kody-w merged 1 commit into
mainfrom
refactor/tier-parity-delete-swarm-server
Apr 21, 2026
Merged

Rewire function_app.py; delete swarm_server.py + chat.py (PR 4/4)#4
kody-w merged 1 commit into
mainfrom
refactor/tier-parity-delete-swarm-server

Conversation

@kody-w

@kody-w kody-w commented Apr 21, 2026

Copy link
Copy Markdown
Owner

Summary

Final phase of the one-stem-many-swarms refactor. Tier 2 becomes a thin Azure Functions adapter over /api/chat, matching Tier 1's surface per CONSTITUTION Article XV (tier parity runs deeper than agents).

Deletions

File Lines Why safe to delete
rapp_brainstem/swarm_server.py 1736 Its capabilities now ship as the 7 swarm-management agents in PR #3. No remaining callers anywhere in the repo.
rapp_brainstem/chat.py 342 LLM tool-calling loop inlined into function_app.py's run_chat (~100 lines).
rapp_brainstem/brainstem_admin_agent.py Root-level sprawl (Article XVI violation). An agents/experimental/ copy already exists.

Total: −2878 lines, +598 lines.

New function_app.py (917 → 470 lines)

  • No SwarmStore, Binder, Assistant, STORE, or multi-tenant routing.
  • No /api/swarm/<guid>/*, /api/t2t/*, or /api/workspace/* surface.
  • Multi-swarm operations flow through /api/chat via the PR Add 7 swarm-management agents (drop-in, stdlib-only) #3 swarm-management agents (Article XIV).
  • Routes: /api/chat, /api/health, /api/llm/status, plus OG aliases (/api/businessinsightbot_function, /api/trigger/copilot-studio).
  • Agent discovery from BRAINSTEM_HOME/agents/ — same glob pattern as brainstem.py.
  • Same tool-calling loop structure, same |||VOICE|||/|||TWIN||| split, same response envelope keys.

build.sh

Now vendors only: llm.py, twin.py, _basic_agent_shim.py, agents/*.py. No more swarm_server.pyserver.py rename.

Stale-reference cleanup

  • tests/run-tests.mjs — removed chat.py from file-presence list.
  • brainstem.py load_agents — removed special-case always-load for the deleted brainstem_admin_agent.py.

Tests

  • NEW: tests/test-function-app-chat.sh — 32 assertions. Exercises run_chat directly (no func start required), verifies envelope parity with Tier 1, VOICE/TWIN split, agent discovery, tool-calling loop behavior under LLM_FAKE=1, BRAINSTEM_HOME swap, and Article XIV compliance.
  • tests/run-tests.mjs — 61/61 pass.

Known parity gap (deferred to PR #5)

brainstem.py's /chat still uses Copilot-only (call_copilot at line 712). For full Article XV tier parity, it should use llm.py's provider dispatch like function_app.py does — so Tier 1 users can point at Azure OpenAI / OpenAI / Anthropic from one .env change.

That change touches the sacred one-liner install path (Article V) and deserves its own PR with its own rollback story. Not bundled here.

Test plan

  • bash tests/test-function-app-chat.sh → 32/32 pass
  • node tests/run-tests.mjs → 61/61 pass
  • bash rapp_swarm/build.sh produces clean _vendored/ with only llm.py/twin.py/_basic_agent_shim.py/agents/
  • python3 -c "import function_app" clean; no SwarmStore/STORE/Assistant symbols
  • python3 -c "import brainstem" still clean after special-case removal
  • grep confirms no remaining chat.py/swarm_server references in docs or code (only experimental/ copy + web/mobile/ secondary surface, already deferred)

🤖 Generated with Claude Code

Final phase of the one-stem-many-swarms refactor: Tier 2 becomes a
thin Azure Functions adapter over the /chat contract, matching Tier 1's
surface per CONSTITUTION Article XV — tier parity runs deeper than
agents.

Deletions (no remaining callers anywhere in the repo):
  • rapp_brainstem/swarm_server.py (1736 lines) — multi-swarm HTTP
    server. Its capabilities now ship as the 7 swarm-management agents
    in PR #3 (deploy/list/info/invoke/seal/snapshot/delete).
  • rapp_brainstem/chat.py (342 lines) — LLM tool-calling loop; logic
    inlined into function_app.py's run_chat (~100 lines).
  • rapp_brainstem/brainstem_admin_agent.py (root-level sprawl,
    Article XVI violation; an `experimental/` copy already exists).

New function_app.py (917 → 470 lines, -49%):
  • No SwarmStore, Binder, Assistant, STORE, or multi-tenant routing.
    /api/swarm/<guid>/* removed entirely — those capabilities flow
    through /api/chat via the PR #3 swarm-management agents.
  • Surface is /api/chat + /api/health + /api/llm/status + the OG
    aliases (/api/businessinsightbot_function, /api/trigger/copilot-studio).
  • Agent discovery from BRAINSTEM_HOME/agents/ (identical pattern to
    brainstem.py's own agents/).
  • Same tool-calling loop, same |||VOICE|||/|||TWIN||| split, same
    response envelope (response, voice_response, twin_response,
    session_id, agent_logs, provider, model).

build.sh now vendors only: llm.py, twin.py, _basic_agent_shim.py, and
agents/*.py (so Tier 2 ships with the same starter + swarm-management
agents Tier 1 users have).

Stale-reference cleanup:
  • tests/run-tests.mjs — removed chat.py from file-presence list.
  • brainstem.py load_agents — removed special-case always-load for
    the deleted brainstem_admin_agent.py.

Tests:
  • NEW: tests/test-function-app-chat.sh — 32 assertions. Exercises
    run_chat directly (no `func start`), verifies envelope parity
    with Tier 1, VOICE/TWIN split, agent discovery, tool-calling loop,
    BRAINSTEM_HOME swap, and Article XIV compliance (no /api/swarm/*,
    /api/t2t/*, /api/workspace/* routes).
  • run-tests.mjs: 61/61.

Known parity gap deferred to PR #5: brainstem.py's /chat still uses
Copilot-only (call_copilot at line 712). For full tier parity, it
should use llm.py's provider dispatch like function_app.py does — so
Tier 1 users can also point at Azure OpenAI / OpenAI / Anthropic from
one .env change. That's a separate, riskier change (touches the
one-liner install path, Article V) and lands independently.

VERSION bumped to 0.10.0 per Article VIII.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kody-w kody-w merged commit a4346bb into main Apr 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant