Rewire function_app.py; delete swarm_server.py + chat.py (PR 4/4)#4
Merged
Merged
Conversation
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>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
rapp_brainstem/swarm_server.pyrapp_brainstem/chat.pyfunction_app.py'srun_chat(~100 lines).rapp_brainstem/brainstem_admin_agent.pyagents/experimental/copy already exists.Total: −2878 lines, +598 lines.
New
function_app.py(917 → 470 lines)SwarmStore,Binder,Assistant,STORE, or multi-tenant routing./api/swarm/<guid>/*,/api/t2t/*, or/api/workspace/*surface./api/chatvia the PR Add 7 swarm-management agents (drop-in, stdlib-only) #3 swarm-management agents (Article XIV)./api/chat,/api/health,/api/llm/status, plus OG aliases (/api/businessinsightbot_function,/api/trigger/copilot-studio).BRAINSTEM_HOME/agents/— same glob pattern asbrainstem.py.|||VOICE|||/|||TWIN|||split, same response envelope keys.build.shNow vendors only:
llm.py,twin.py,_basic_agent_shim.py,agents/*.py. No moreswarm_server.py→server.pyrename.Stale-reference cleanup
tests/run-tests.mjs— removedchat.pyfrom file-presence list.brainstem.py load_agents— removed special-case always-load for the deletedbrainstem_admin_agent.py.Tests
tests/test-function-app-chat.sh— 32 assertions. Exercisesrun_chatdirectly (nofunc startrequired), verifies envelope parity with Tier 1, VOICE/TWIN split, agent discovery, tool-calling loop behavior underLLM_FAKE=1,BRAINSTEM_HOMEswap, and Article XIV compliance.tests/run-tests.mjs— 61/61 pass.Known parity gap (deferred to PR #5)
brainstem.py's/chatstill uses Copilot-only (call_copilotat line 712). For full Article XV tier parity, it should usellm.py's provider dispatch likefunction_app.pydoes — so Tier 1 users can point at Azure OpenAI / OpenAI / Anthropic from one.envchange.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 passnode tests/run-tests.mjs→ 61/61 passbash rapp_swarm/build.shproduces clean_vendored/with onlyllm.py/twin.py/_basic_agent_shim.py/agents/python3 -c "import function_app"clean; noSwarmStore/STORE/Assistantsymbolspython3 -c "import brainstem"still clean after special-case removalchat.py/swarm_serverreferences in docs or code (onlyexperimental/copy +web/mobile/secondary surface, already deferred)🤖 Generated with Claude Code