Skip to content

Feat/agent runtime local cloud orchestration - #467

Open
Unclebaffa wants to merge 2 commits into
Bitcoindefi:mainfrom
Unclebaffa:feat/agent-runtime-local-cloud-orchestration
Open

Feat/agent runtime local cloud orchestration#467
Unclebaffa wants to merge 2 commits into
Bitcoindefi:mainfrom
Unclebaffa:feat/agent-runtime-local-cloud-orchestration

Conversation

@Unclebaffa

Copy link
Copy Markdown
Contributor

Implementation Summary: [EPIC] Agent Runtime — Local Lightweight Agents + Cloud Orchestration

Executive Overview

We implemented the real backend Agent Runtime for Open-Stellar, transforming agents from static UI state into real, executable TypeScript actors capable of receiving tasks, executing custom handlers, emitting lifecycle events, passing messages, persisting state across server restarts, and deploying locally via CLI or to serverless edge platforms (Vercel Edge Functions).


🚀 Key Features Implemented

1. TypeScript Agent SDK & Lifecycle Hooks

  • SDK Entry Point (lib/agent-runtime/sdk.ts): Created the high-level AgentSDK class and createAgent() builder function allowing developer-friendly agent creation.
  • Lifecycle Event Hooks (lib/agent-runtime/agent.ts): Implemented event hooks for full agent lifecycle management:
    • onStart: Triggered when agent process starts running.
    • onStop: Triggered when agent shuts down cleanly.
    • onTask: Custom task handler for receiving and processing incoming tasks.
    • onMessage: Handles inter-agent communication messages.
    • onError: Intercepts runtime task execution errors.
    • onStateChange: Monitors agent state transitions (idle $\rightarrow$ running $\rightarrow$ working $\rightarrow$ stopped/degraded).

2. Local CLI Tool (bin/open-stellar.js)

  • Executable CLI (open-stellar): Built a Node CLI executable with permissions (#!/usr/bin/env node) registered in package.json under "bin": { "open-stellar": "./bin/open-stellar.js" }.
  • Command Set:
    • npx open-stellar agent start --name <Name> --district <District>: Instantiates an agent, registers its metadata, updates status to active, and persists state to disk.
    • npx open-stellar agent list: Displays registered and persisted agents formatted in an ASCII table.
    • npx open-stellar agent task --id <AgentID> --title <TaskTitle>: Dispatches tasks directly to active agents via CLI.

3. State Persistence (lib/agent-runtime/persistence.ts)

  • JSON File Store (.data/agent-state.json): Implemented safe local state persistence for agents and their runtime metrics.
  • Edge Runtime Safety: Uses dynamic Node eval("require") checks to ensure serverless Edge Function bundles (such as /api/og/agent/[id]) compile cleanly without bundling native filesystem modules (node:fs, node:path).
  • Atomic Writes: Safe atomic write pattern with fallback handling to survive process crashes and power interruptions.

4. Cloud & Serverless Deployments (lib/agent-runtime/cloud-deploy.ts)

  • Serverless Handlers: Added createServerlessAgentHandler() (for standard Node.js serverless functions) and createEdgeAgentHandler() (for Vercel Edge Runtime / Cloudflare Workers).
  • REST Protocol: Configured standard HTTP endpoints for receiving task payloads via POST /api/agents/:id/task and returning JSON task results.

5. Canvas & UI Dynamic Hydration (lib/data.ts)

  • Dynamic Agent Hydration: Updated createAgents() in lib/data.ts to dynamically merge persisted and CLI-started agents into the frontend canvas state, ensuring agents started via CLI instantly appear on the canvas and interactive UI.

6. Store File Locking Reliability Fixes

  • Atomic File Writing Fallback (copyFileSync): Updated lib/protocols/x402-receipt-store.ts, lib/agents/agent-error-store.ts, and lib/agent-runtime/persistence.ts with copyFileSync and unlinkSync fallback handling. This eliminates Windows EPERM file locking errors when running parallel tests or background file updates.

🧪 Comprehensive Testing & Verification

Unit Test Suites Created

  1. __tests__/agent-runtime/sdk.test.ts: Validates agent creation, task execution, lifecycle hooks (onStart, onStop, onError), and metrics tracking.
  2. __tests__/agent-runtime/persistence.test.ts: Verifies JSON state persistence, empty file recovery, and agent state upserts.
  3. __tests__/agent-runtime/cli.test.ts: End-to-end testing of open-stellar agent start and open-stellar agent list process execution.

Full Test Suite Results (npx vitest run)

  • 91 / 91 Test Files Passed
  • 579 / 579 Unit Tests Passed (100% pass rate)

🛡️ Code Quality & Build Checks

Verification Check Tool / Command Result
Linting npm run lint 0 Errors (55 non-blocking warnings)
Type Checking npx tsc --noEmit 0 Type Errors
Security Audit npm run secretlint 0 Secrets / 0 Errors
Code Formatting npx prettier --check 100% Formatted
Production Build npm run build Clean Next.js Build (64/64 static pages generated)

📦 Git Branch & Remote Sync

  • Branch: feat/agent-runtime-local-cloud-orchestration
  • Upstream Status: Pushed and tracked on remote origin/feat/agent-runtime-local-cloud-orchestration.

Closes #17

@Unclebaffa
Unclebaffa force-pushed the feat/agent-runtime-local-cloud-orchestration branch 5 times, most recently from 0dd7418 to 6fa18be Compare July 26, 2026 10:19
Bumps [resend](https://github.com/resend/resend-node) from 6.17.1 to 6.17.2.
- [Release notes](https://github.com/resend/resend-node/releases)
- [Changelog](https://github.com/resend/resend-node/blob/canary/CHANGELOG.md)
- [Commits](resend/resend-node@v6.17.1...v6.17.2)

---
updated-dependencies:
- dependency-name: resend
  dependency-version: 6.17.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@Unclebaffa
Unclebaffa force-pushed the feat/agent-runtime-local-cloud-orchestration branch from 6fa18be to d42d9c0 Compare July 26, 2026 10:41
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

[EPIC] Agent Runtime — local lightweight agents + cloud orchestration

1 participant