Agent routing: first-party network tools invisible to chat surface (polymarket, kalshi)
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):
pnpm dev:appfrom a worktree offupstream/main(withOPENHUMAN_APP_ENV=staging+BACKEND_URL=https://staging-api.tinyhumans.aiin.env).- Wait for boot — confirm logs show
[core] OpenHuman core is ready — listening on http://127.0.0.1:7788. - Open chat, send:
hey! can you use kalshi tool to list markets. - Observe: agent says no kalshi available; lists only composio-connected services.
- 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):
src/openhuman/agent/agents/orchestrator/agent.toml:47-69lists 9 subagents.src/openhuman/tools/orchestrator_tools.rs::collect_orchestrator_toolssynthesises onedelegate_*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"].- Orchestrator LLM only ever sees
delegate_*tools — never rawkalshi/polymarket. tools_agenthas[tools] wildcard = {}(tools_agent/agent.toml). At runtimesrc/openhuman/agent/harness/subagent_runner/tool_prep.rs:165resolves wildcard as "let all tools through" →KalshiTool(name()="kalshi") andPolymarketTool(name()="polymarket") ARE intools_agent's inventory.- But
delegate_tools_agent.when_to_useadvertises 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.tomlid = "markets_agent"delegate_name = "do_prediction_markets"→ orchestrator surfacesdelegate_do_prediction_marketswhen_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 withcrypto_agentinstead)temperature = 0.2,max_iterations = 8,sandbox_mode = "none"- Mirror
crypto_agentomit 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. Adaptcrypto_agent/prompt.md's safety contract; do NOT inherit wallet/chain language.markets_agent/mod.rs+markets_agent/prompt.rs— thin wrappers mirroringcrypto_agentshape.
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 viadelegate_do_prediction_markets).src/openhuman/tools/orchestrator_tools.rs::tests→ new test assertingmarkets_agentsubagent synthesisesdelegate_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_agentto 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_useto 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 forpolymarket. - [ ] 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, NOTdelegate_do_prediction_markets. - [ ] Loader contract —
cargo test --lib agent::agents::loaderpasses including new markets_agent tests. - [ ] Synthesis contract —
cargo test --lib tools::orchestrator_toolspasses including newdelegate_do_prediction_marketssynthesis 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)