Skip to content

feat: wire execute() flow — integrate memory, tools, broker into kernel#2

Merged
Aakashbhardwaj27 merged 1 commit intomainfrom
feat/execute-flow
Mar 28, 2026
Merged

feat: wire execute() flow — integrate memory, tools, broker into kernel#2
Aakashbhardwaj27 merged 1 commit intomainfrom
feat/execute-flow

Conversation

@Aakashbhardwaj27
Copy link
Copy Markdown
Contributor

@Aakashbhardwaj27 Aakashbhardwaj27 commented Mar 28, 2026

feat: Wire execute() flow — integrate memory, tools, broker into kernel

What does this PR do?

This is the most critical PR in Phase 1. It takes the five standalone modules (Kernel, MemoryBus, ToolRouter, MessageBroker, Scheduler) and wires them into a single, working runtime.

Before this PR: you could spawn an agent process and manage its lifecycle, but it couldn't do anything — no execution, no memory, no tool access.

After this PR: kernel.execute() builds a full ExecutionContext and calls the agent's handler with working memory, tool invocation, message publishing, and event emission.

Why?

This closes the gap between "modules exist" and "AgentVM actually runs agents." Without this, the project is scaffolding. With this, it's a runtime.

Changes

src/core/kernel.ts — Major rewrite

  • Kernel now instantiates MemoryBus, ToolRouter, and MessageBroker internally
  • Exposes them as kernel.memory, kernel.tools, kernel.broker
  • New kernel.execute(processId, taskInput) method:
    • Validates process state and agent handler
    • Builds ExecutionContext with ctx.memory, ctx.useTool(), ctx.publish(), ctx.emit(), ctx.signal
    • Calls agent handler, tracks duration, stores result metadata
    • On crash: transitions process to crashed state with error details
  • ctx.useTool() enforces agent's declared tool permissions
  • kernel.terminate() cleans up process memory (unless persistent: true)
  • Convenience: kernel.registerTool(), kernel.createChannel()
  • New events: execution:started/completed/failed, tool:invoked/completed/registered, channel:created

tests/unit/core.test.ts — Expanded test coverage

  • All existing tests preserved
  • New: Kernel.execute() suite (7 tests)
  • New: Kernel + Memory Integration suite (3 tests — isolation, cleanup, persistence)
  • New: Kernel + Tool Integration suite (4 tests — invocation, permissions, events)
  • New: Kernel + Broker Integration suite (1 test — publish from handler)

examples/hello-world.ts — Rewritten for real usage

  • Shows the complete flow: register tool → define agent with handler → spawn → execute (twice, showing memory persistence) → terminate

How to test

npm test          # all tests should pass
npm run build     # should build clean (no TS errors)
npm run lint      # should pass

# run the example
npx tsx examples/hello-world.ts

Roadmap context

This completes the core of Phase 1 M1.1 and M1.2 from [ROADMAP.md](../ROADMAP.md):

  • Kernel class with lifecycle hooks — done
  • Agent execution with handler — done (this PR)
  • MemoryBus wired into Kernel — done (this PR)
  • ToolRouter wired into Kernel — done (this PR)
  • MessageBroker wired into Kernel — done (this PR)

What's next

  • CLI (agentvm init, agentvm spawn, agentvm ps, agentvm kill)
  • 80%+ test coverage
  • API reference docs (auto-generated)

@Aakashbhardwaj27 Aakashbhardwaj27 merged commit 9724bb4 into main Mar 28, 2026
3 checks passed
@Aakashbhardwaj27 Aakashbhardwaj27 deleted the feat/execute-flow branch March 28, 2026 20:01
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