Skip to content

factory: an organization's server runs its workstreams' agents with the organization's key - #2641

Merged
santoshkumarradha merged 5 commits into
work/teamsfrom
w2/e6b-server-agent
Nov 13, 2026
Merged

santoshkumarradha merged 5 commits into
work/teamsfrom
w2/e6b-server-agent

Conversation

@santoshkumarradha

Copy link
Copy Markdown
Member

What this does

Before this PR, a PATCH of agent_runner to server answered 422 (W8, #2633). Now codeaf factory serve runs each workstream's agent itself, using the organization's own model key.

Org model key

  • GET /v1/org/keys, PUT|DELETE /v1/org/keys/{provider} (operator only).
  • The key is stored in org-keys.json (0600). It is answered back only as its last four characters.
  • Engine methods: factory.org_keys, factory.org_key_set, factory.org_key_delete.

Server agent

  • Routes: GET /v1/workstreams/{id}/agent?since=, POST …/agent/messages, POST …/agent/stop.
  • Events agent.entry and agent.state, filtered by view. The engine relays them as factory.org_workstream_agent.
  • Engine methods factory.org_workstream_agent{,_send,_stop}; hello word org_agent_server.
  • Who can do what:
    • Anyone with edit talks to it and can stop it.
    • Viewers read the conversation.
    • A second message while it answers someone else is a 409, reason: busy, by.
  • It reuses internal/session through a new Config.Workstream door. Its belt is exactly one tool, workstream_pages.
  • Spend is posted with by = the asker, chat agent.

agent_runners answers [driver, server] once there is a runner and a key. Choosing server lets go of every driver's hand.

Honest scope: what the server agent lacks

It can:

  • Read the workstream: pages, decisions, sources, links, budget.
  • Read one page whole.
  • Write a page, or make a new page.
  • Propose a decision.

It cannot:

  • Run a shell.
  • Read or write files.
  • Touch a repository.
  • Start factory jobs, so the workstream's go-aheads are not used yet.
  • Use the web, memory, machines or subagents.

Pages being co-edited (Yjs): the server cannot write Yjs.

  • If the page's live doc is empty, the agent's text goes into the body_md mirror, and the first person to open the page seeds from it.
  • Otherwise the text is kept as a page version with reason agent, which anyone with edit restores from history.

Budget: it is checked when a message is admitted. A turn already running may finish past it.

Wire docs

  • docs/design/app-v3/PROTOCOL.md is updated in this PR.
  • ~/work/teams-wave/WAVE2.md §4.3 gained "Server mode as built (E6b)". That file is outside the repository and was edited in place.

Proof

Live run, with the real bin/codeaf factory serve, a throwaway HOME, a fake model behind CODEAF_BASE_URL, and four signed-in sessions (owner/operator, santosh and abir editing, mia viewing):

  • Key access: abir got 403 on the keys.
  • Key stored: the operator set a key; it was answered back as …WXYZ, and the file is 0600.
  • Runner offered: agent_runners became [driver, server], and the PATCH to server succeeded.
  • Viewer: mia read with can_talk false and got 403 on POST.
  • Busy: santosh talked; while he was answered, abir got 409 "still answering santosh".
  • Conversation:
    • It went person → 3 steps → answer.
    • A page was written as santosh.
    • A decision was proposed.
    • Spend was posted to santosh.
  • Events: abir and mia each received the 5 agent.entry and 2 agent.state events.
  • Key on the wire: every model call carried the org key.
  • Restart: the conversation survived a server restart.
  • Stop: the owner (no edit) got 403; santosh stopped it, giving the note "Stopped by santosh.", and the model call was cancelled.

No real model key was used.

Tests

  • internal/factory/serve/workstream_agent_test.go: 7 tests.
  • cmd/codeaf: factory_workstream_agent_test.go and appfactory_org_agent_test.go.
  • internal/session/tools_workstream_test.go.
  • Manual probes in internal/manual/chat_test.go.
  • make pr-ready BASE=d0c8ab2ac (the real work/teams head).

Desk half: codeaf-desk PR into work/rail-personal (follows).

santoshkumarradha and others added 5 commits November 13, 2026 16:19
…he organization's key

The server half of `agent_runner: server` (WAVE2.md §4.3): the operator's
model key store (GET/PUT/DELETE /v1/org/keys, last four only), one agent
per workstream on the server built from internal/session with a belt of
`workstream_pages` alone, its conversation wire (GET .../agent,
POST .../agent/messages, POST .../agent/stop, events agent.entry and
agent.state), spend posted under the asker, and the engine's
factory.org_key* / factory.org_workstream_agent* methods behind hello
`org_agent_server`. `agent_runners` offers server once a runner and a key
exist.

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
…e one provider name

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
@santoshkumarradha
santoshkumarradha merged commit 442e39f into work/teams Nov 13, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the w2/e6b-server-agent branch November 13, 2026 21:47
santoshkumarradha added a commit that referenced this pull request Nov 13, 2026
Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
ZeroPoint95 pushed a commit that referenced this pull request Nov 24, 2026
…he organization's key (#2641)

Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
ZeroPoint95 pushed a commit that referenced this pull request Nov 24, 2026
Assisted-by: CodeAF
Co-Authored-By: CodeAF <[email protected]>
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