Skip to content

feat: wire full agent loop into WebSocket chat handler#3367

Closed
liorwn wants to merge 1 commit intozeroclaw-labs:masterfrom
liorwn:feat/ws-tool-execution
Closed

feat: wire full agent loop into WebSocket chat handler#3367
liorwn wants to merge 1 commit intozeroclaw-labs:masterfrom
liorwn:feat/ws-tool-execution

Conversation

@liorwn
Copy link
Copy Markdown

@liorwn liorwn commented Mar 12, 2026

Summary

The /ws/chat endpoint currently calls provider.chat_with_history() directly, which only returns raw LLM output without executing tool calls. This means WebSocket clients cannot use tools β€” a significant gap vs the CLI agent mode and a blocker for platform integrations that rely on WebSocket.

This PR replaces the direct provider call with process_message(), which runs the full agent loop: tool parsing, execution (shell, file, memory, etc.), security policy enforcement, and multi-turn tool iterations.

Changes

  • Replace chat_with_history() with process_message() in handle_socket()
  • Add {"type": "thinking"} event so clients can show a loading state during tool execution
  • Auto-save user/assistant messages to memory (respects auto_save config)
  • Update module doc comments

Protocol

No breaking changes. Same message format:

Client β†’ {"type":"message","content":"..."}
Server β†’ {"type":"thinking"}           ← NEW (optional, clients can ignore)
Server β†’ {"type":"done","full_response":"..."}
Server β†’ {"type":"error","message":"..."}

Motivation

We're building a managed AI agent hosting platform (getbotler.ai) and evaluated ZeroClaw as a replacement for OpenClaw on our dedicated tier. The <1s cold start and <5MB RAM footprint are exactly what we need. The only blocker was that WebSocket chat didn't execute tools β€” this PR fixes that.

Related: #88 (feature parity checklist mentions tool execution gap)

Testing

Tested locally with zeroclaw gateway + WebSocket client. Tool calls (shell, file_read, file_write, memory_store) all execute correctly through the WebSocket endpoint after this change.

The /ws/chat endpoint previously called provider.chat_with_history()
directly, which only returned raw LLM output without executing tool
calls. This meant WebSocket clients could not use tools β€” a significant
gap vs the CLI agent mode.

This commit replaces the direct provider call with process_message(),
which runs the full agent loop: tool parsing, execution (shell, file,
memory, etc.), security policy enforcement, and multi-turn tool
iterations. WebSocket clients now get identical agentic behaviour to
`zeroclaw agent -m "..."`.

Changes:
- Replace chat_with_history() with process_message() in handle_socket()
- Add "thinking" event so clients can show loading state during tool execution
- Auto-save user/assistant messages to memory (respects auto_save config)
- Update module doc comments to reflect the new behaviour

The protocol remains the same:
  Client β†’ {"type":"message","content":"..."}
  Server β†’ {"type":"thinking"}
  Server β†’ {"type":"done","full_response":"..."}
  Server β†’ {"type":"error","message":"..."}

Resolves the tool execution gap noted in zeroclaw-labs#88.
@theonlyhennygod
Copy link
Copy Markdown
Collaborator

Closing β€” CI failed across Build, Lint, Test, and Check with compilation error: this method takes 4 arguments but 3 arguments were supplied. The API has changed on master. Please rebase on latest master, fix the method call signatures, and open a fresh PR. Thanks @liorwn!

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.

2 participants