openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Agent routing: first-party network tools invisible to chat surface (polymarket, kalshi)

Open oxoxDev opened this issue 6 months ago • 0 comments

Summary

The chat orchestrator cannot route requests for first-party network tools (polymarket, kalshi) — both tools are registered in the tools registry and accessible over JSON-RPC, but the chat agent reports them as "not connected" because the orchestrator's delegation surface advertises no specialist for prediction-market venues. Hyperliquid (venue 3/3) will inherit the same gap.

Problem

What happened: On staging build (commit e68fa585, branch feat/1398-kalshi) the chat agent replied to "use kalshi tool to list markets" with: "I don't have a kalshi tool available right now. The connected integrations I can work with are github, gmail, and slack." Same response for polymarket despite PR #2145 shipping that capability.

What we expected: Orchestrator routes prediction-market requests to a specialist that dispatches kalshi.list_markets / polymarket.list_markets via the existing tools registry.

Impact: Both PR #2145 (Polymarket, merged) and PR #2329 (Kalshi, in review) functionally unreachable from chat despite passing tests + RPC dispatch working end-to-end. Defeats the purpose of #1398 (prediction-market trading via the agent).

Steps to reproduce (verified 2026-05-21 on staging dev:app):

  1. pnpm dev:app from a worktree off upstream/main (with OPENHUMAN_APP_ENV=staging + BACKEND_URL=https://staging-api.tinyhumans.ai in .env).
  2. Wait for boot — confirm logs show [core] OpenHuman core is ready — listening on http://127.0.0.1:7788.
  3. Open chat, send: hey! can you use kalshi tool to list markets.
  4. Observe: agent says no kalshi available; lists only composio-connected services.
  5. Same outcome for list polymarket markets.

Environment: openhuman v0.54.2, macOS 25.2.0, CEF runtime, in-process core (post-#1061).

Root cause

Verified via code reads (no speculation):

  1. src/openhuman/agent/agents/orchestrator/agent.toml:47-69 lists 9 subagents. src/openhuman/tools/orchestrator_tools.rs::collect_orchestrator_tools synthesises one delegate_* tool per entry. Boot logs confirm exactly 9 delegations: ["plan", "run_code", "review_code", "delegate_tools_agent", "archive_session", "research", "do_crypto", "delegate_to_integrations_agent", "create_skill"].
  2. Orchestrator LLM only ever sees delegate_* tools — never raw kalshi / polymarket.
  3. tools_agent has [tools] wildcard = {} (tools_agent/agent.toml). At runtime src/openhuman/agent/harness/subagent_runner/tool_prep.rs:165 resolves wildcard as "let all tools through" → KalshiTool (name()="kalshi") and PolymarketTool (name()="polymarket") ARE in tools_agent's inventory.
  4. But delegate_tools_agent.when_to_use advertises only "shell, file I/O, HTTP, web search, memory". Orchestrator's LLM routes by reading these blurbs; prediction-market intent matches no delegate, so it falls back to the composio connection inspector and reports "not connected".

The capabilities exist in the tree. The routing layer can't find them.

Solution

Add a new specialist agent markets_agent modelled on crypto_agent (precedent: src/openhuman/agent/agents/crypto_agent/agent.toml).

New files (~200 LOC + ~50 LOC tests):

  • src/openhuman/agent/agents/markets_agent/agent.toml
    • id = "markets_agent"
    • delegate_name = "do_prediction_markets" → orchestrator surfaces delegate_do_prediction_markets
    • when_to_use = "Prediction-market & event-contract trading specialist — drives Polymarket (CTF Exchange), Kalshi (KalshiEX), and event-contract venues. Use for: market discovery (list/get markets, events, orderbooks); portfolio reads (positions, balance, open orders, fills); and (with explicit user approval) place_order / cancel_order. Always browse before placing; always surface approval gates to the user; refuse trade actions on missing API credentials or unknown ticker shape."
    • [tools] named = ["polymarket", "kalshi"] (Hyperliquid placement deferred to its own PR — perps may belong with crypto_agent instead)
    • temperature = 0.2, max_iterations = 8, sandbox_mode = "none"
    • Mirror crypto_agent omit flags (omit_identity / omit_memory_context / omit_skills_catalog = true, omit_safety_preamble = false); [model] hint = "agentic"
  • markets_agent/prompt.md — read → propose order with side/count/price → user approval → execute. Refuse on missing creds, unknown ticker shape, price out of 1–99c cents range. Adapt crypto_agent/prompt.md's safety contract; do NOT inherit wallet/chain language.
  • markets_agent/mod.rs + markets_agent/prompt.rs — thin wrappers mirroring crypto_agent shape.

Edited files:

  • src/openhuman/agent/agents/orchestrator/agent.toml:47-69 → insert "markets_agent" after "crypto_agent", before { skills = "*" }, with comment matching the crypto_agent comment block (lines 55-60).
  • src/openhuman/agent/agents/loader.rs → register markets_agent + 3 new tests.
  • src/openhuman/agent/agents/mod.rs → pub mod markets_agent;.
  • src/openhuman/agent/agents/tools_agent/agent.toml → add disallow entry for ["polymarket", "kalshi"] so the wildcard no longer surfaces them (single canonical route via delegate_do_prediction_markets).
  • src/openhuman/tools/orchestrator_tools.rs::tests → new test asserting markets_agent subagent synthesises delegate_do_prediction_markets.

NO changes required to: tools/ops.rs, tools/impl/network/{kalshi,polymarket}.rs, RPC controllers, capability catalog, backend, frontend.

Alternatives considered + rejected

  • Extend crypto_agent to include polymarket/kalshi → conflates wallet-signing safety contract with USD market-buy contract; weakens routing signal as the blurb grows multi-topic.
  • Tweak tools_agent.when_to_use to mention prediction markets → wildcard means every future registry tool becomes implicitly trade-routable; no venue-specific safety preamble.

Acceptance criteria

  • [ ] Repro gone — On staging dev:app, chat agent dispatches kalshi.list_markets (cred-guard error bubbles to user) when user says "list kalshi markets". Same for polymarket.
  • [ ] Approval gate verified — "place a kalshi order on FED-25NOV-Y side yes count 1 yes_price 50" surfaces "Re-invoke with arguments.approved = true ..." verbatim through the agent reply.
  • [ ] crypto_agent regression — "send 5 USDC to vitalik.eth" still routes to delegate_do_crypto, NOT delegate_do_prediction_markets.
  • [ ] Loader contract — cargo test --lib agent::agents::loader passes including new markets_agent tests.
  • [ ] Synthesis contract — cargo test --lib tools::orchestrator_tools passes including new delegate_do_prediction_markets synthesis test.
  • [ ] Quality gates — cargo check --workspace, cargo fmt --check, scoped clippy on new files clean.
  • [ ] Diff coverage ≥ 80% — fix PR meets changed-lines gate.

Related

  • Refs #1398 — Trading integrations (Polymarket + Kalshi + Hyperliquid)
  • Refs #2145 — Polymarket merged; tool registered but unreachable from chat (this issue closes the gap for it)
  • Refs #2329 — Kalshi in review; tool registered but unreachable from chat (this issue closes the gap for it)
  • Informs venue 3/3 plan — Hyperliquid routing decision (markets_agent vs crypto_agent) gets made when its PR opens.
  • Architecture refs: gitbooks/developing/architecture/agent-harness.md, src/openhuman/agent/agents/crypto_agent/ (precedent)

oxoxDev avatar May 21 '26 08:05 oxoxDev