Skip to content

[Task]: Extract shared agent startup sequence into packages/common #31

Description

@grantfox-oss

Each of the five specialist agents (stellar-oracle, analysis-agent, reporter-agent, web-intel-agent, computation-agent) has an identical startup sequence:

  1. Load env vars, validate required ones
  2. Load or generate a keypair from wallets.json
  3. Call POST ${REGISTRY_URL}/register with the agent manifest
  4. Start the HTTP server
  5. Log the agent address and listening port

This is duplicated in each agent's src/server.ts. Any change (e.g., adding a heartbeat after registration, adding the USDC balance warning from issue #19) requires touching five files.

Extract this into a shared registerAgent helper in packages/common/src/agent-startup.ts:

export interface AgentStartupOptions {
  manifest: AgentManifest;
  walletKey: string;      // key in wallets.json, e.g. "stellar_oracle"
  onReady?: (keypair: Keypair) => void;
}

export async function registerAgent(opts: AgentStartupOptions): Promise<void>;

The helper handles keypair loading, registration POST with retry (3 attempts), heartbeat setup, and startup log lines. Each agent's server.ts is reduced to defining its manifest and calling registerAgent.

This change should not alter any external behavior.

Acceptance criteria

  • packages/common/src/agent-startup.ts exports a registerAgent function
  • At least two agents are migrated to use registerAgent (the remaining three can follow as separate PRs)
  • The migrated agents' startup behavior is identical to before (same log output, same registration payload)
  • npm run typecheck and npm run lint pass for all packages

Relevant files

  • packages/common/src/ (new file)
  • packages/stellar-oracle/src/server.ts
  • packages/analysis-agent/src/server.ts
  • Other agent server files (for reference)
  • packages/common/src/types.ts

Notes for contributors

If you'd like to work on this, comment below so we can assign it to you.
Questions welcome — see CONTRIBUTING.md for setup
and workflow.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions