Skip to content

🔨 chore(api): add POST /api/agent/tool-result callback endpoint#13764

Merged
arvinxx merged 1 commit into
canaryfrom
feat/lobe-7065-tool-result-callback-api
Apr 13, 2026
Merged

🔨 chore(api): add POST /api/agent/tool-result callback endpoint#13764
arvinxx merged 1 commit into
canaryfrom
feat/lobe-7065-tool-result-callback-api

Conversation

@arvinxx

@arvinxx arvinxx commented Apr 12, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • ✨ feat

🔗 Related Issue

Fixes LOBE-7065 (Phase 6.1c — part of LOBE-7041 Gateway client tool calling)

🔀 Description of Change

Adds the callback endpoint that Agent Gateway uses to forward client-side tool execution results to the server-side agent loop. Companion to `ToolResultWaiter` (LOBE-7064) — the endpoint LPUSHes, the waiter BLPOPs.

Protocol:

  • `POST /api/agent/tool-result`
  • Auth: `Authorization: Bearer ${AGENT_GATEWAY_SERVICE_TOKEN}`
  • Body: `{ toolCallId: string, content: string|null, success: boolean, error?: { message, type? } }`
  • Response: `204` success, `401` bad token, `400` bad body, `503` redis/config missing

Redis write: LPUSH + EXPIRE 120s pipelined. Duplicates are fine — they sit under TTL until expired, since BLPOP only pops the first. Idempotency isn't required.

No caller wires this in yet — end-to-end flow lands with LOBE-7068 (RuntimeExecutors executor='client' branch).

🧪 How to Test

  • `bunx vitest run src/app/\(backend\)/api/agent/tool-result/tests/route.test.ts` — 6/6 pass (token missing/wrong, env missing, invalid body, redis unavailable, happy path, redis error)
  • No tests needed

@vercel

vercel Bot commented Apr 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 13, 2026 2:20am

Request Review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @arvinxx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b53e92ae6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +72 to +75
.pipeline()
.lpush(key, JSON.stringify(parsed.data))
.expire(key, TOOL_RESULT_TTL_SECONDS)
.exec();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Check pipeline exec results for Redis command errors

The handler treats pipeline().exec() as all-or-nothing and only handles thrown exceptions, but ioredis reports per-command failures in the returned tuple array ([err, result]) without necessarily rejecting (mirrored by IoRedisRedisProvider.pipeline().exec typing in src/libs/redis/redis.ts). If LPUSH or EXPIRE fails (e.g., key has wrong Redis type), this path still returns 204, so the caller thinks delivery succeeded while the agent loop keeps waiting for a missing tool result.

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Apr 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.36066% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.53%. Comparing base (12bbc56) to head (a412575).
⚠️ Report is 2 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #13764      +/-   ##
==========================================
+ Coverage   66.52%   66.53%   +0.01%     
==========================================
  Files        2023     2024       +1     
  Lines      171650   171711      +61     
  Branches    19971    20751     +780     
==========================================
+ Hits       114182   114242      +60     
- Misses      57344    57345       +1     
  Partials      124      124              
Flag Coverage Δ
app 58.59% <98.36%> (+0.01%) ⬆️
database 92.49% <ø> (ø)
packages/agent-runtime 79.72% <ø> (ø)
packages/context-engine 83.38% <ø> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 74.74% <ø> (ø)
packages/model-bank 99.86% <ø> (ø)
packages/model-runtime 84.20% <ø> (ø)
packages/prompts 69.24% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.14% <ø> (ø)
packages/web-crawler 88.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 65.70% <ø> (ø)
Services 52.19% <ø> (ø)
Server 66.14% <ø> (ø)
Libs 52.83% <ø> (ø)
Utils 91.07% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Agent Gateway forwards client tool execution results to this endpoint;
the handler LPUSHes into a per-toolCallId Redis list with a 120s TTL so
the server-side agent loop's BLPOP can wake and continue.

- Auth via AGENT_GATEWAY_SERVICE_TOKEN bearer header
- Zod-validated body: { toolCallId, content, success, error? }
- Key: tool_result:{toolCallId}
- Idempotency not required; duplicates sit under TTL until expired

No runtime caller yet — wiring lands with the BLPOP waiter in LOBE-7068.

Covered by unit tests (6 cases: missing/wrong token, missing token env,
invalid body, Redis unavailable, happy path, Redis write error).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@arvinxx arvinxx force-pushed the feat/lobe-7065-tool-result-callback-api branch from b53e92a to a412575 Compare April 13, 2026 02:10
@arvinxx arvinxx changed the title ✨ feat(api): add POST /api/agent/tool-result callback endpoint 🔨 chore(api): add POST /api/agent/tool-result callback endpoint Apr 13, 2026
@arvinxx arvinxx merged commit c60563f into canary Apr 13, 2026
33 of 34 checks passed
@arvinxx arvinxx deleted the feat/lobe-7065-tool-result-callback-api branch April 13, 2026 02:35
canisminor1990 added a commit that referenced this pull request Apr 16, 2026
# 🚀 LobeHub v2.1.50 (20260416)

**Release Date:** April 16, 2026\
**Since v2.1.49:** 107 commits · 101 merged PRs · 13 contributors

> This weekly release focuses on improving runtime stability and gateway
execution consistency, while making Home/Recents workflows faster to
navigate and easier to manage in daily use.

---

## ✨ Highlights

- **Server-side Human Approval Flow** — Agent runtime now supports more
reliable approve/reject/reject-continue handling in gateway mode,
reducing stalled execution paths in long-running tasks. (#13829, #13863,
#13873)

- **Message Gateway End-to-End Hardening** — Gateway message flow, queue
handling, tool callback routing, and stop interruption behavior were
strengthened for better execution continuity. (#13761, #13816, #13820,
#13815)

- **Client Tool Execution in Gateway Mode** — Client-executor tools now
run more predictably across gateway and desktop callers, with improved
executor dispatch behavior. (#13792, #13790)

- **Home / Recents / Sidebar Upgrade** — Sidebar layout, custom sort,
recents operations, and profile actions were improved to reduce
navigation friction in active sessions. (#13719, #13812, #13723, #13739,
#13878, #13734)

- **Agent Workspace and Documents Expansion** — Working panel and agent
document workflows were expanded and polished for better day-to-day
agent operations. (#13766, #13857)

- **Provider and Model Compatibility Improvements** — Added GLM-5.1
support and refined model/provider edge-case handling, including schema
and error-path fixes. (#13757, #13806, #13736, #13740)

---

## 🏗️ Core Agent & Architecture

### Agent runtime and intervention lifecycle

- Added server-side human approval and improved runtime coordination
across approve/reject decision paths. (#13829, #13863)
- Improved interrupted-task handling and operation lifecycle consistency
to reduce half-finished runtime states. (#13714)
- Refined error classification and payload propagation so downstream
surfaces receive clearer actionable errors. (#13736, #13740)

### Execution model and dispatch behavior

- Introduced executor-aware runtime behavior to better separate
client/server tool execution semantics. (#13758)
- Improved tool/plugin resolution and manifest handling to avoid runtime
failures on malformed inputs. (#13856, #13840, #13807)

---

## 📱 Gateway & Platform Integrations

- Added message gateway support and strengthened queue/error behavior
for more stable cross-channel execution. (#13761, #13816, #13820)
- Improved gateway callback pipeline with protocol and API additions for
`tool_execute` / `tool_result`. (#13762, #13764, #13765)
- Improved bot/channel reliability and DM/slash handling in
Discord-related paths. (#13805, #13724)

---

## 🖥️ CLI & User Experience

- Improved CLI reliability across message/topic operations and
build/minify-related paths. (#13731, #13888)
- Added image-to-video options and improved command behavior for
generation workflows. (#13788)
- Improved desktop runtime behavior for remote fetch and Linux
notification urgency handling. (#13789, #13782)

---

## 🔧 Tooling

- Extracted gateway stream client into `@lobechat/agent-gateway-client`
to centralize protocol usage and reduce duplication. (#13866)
- Improved built-in tool coverage and runtime support, including GTD
server runtime and missing lobe-kb tools. (#13854, #13876)
- Updated skill and frontmatter consistency in workflow tooling.
(#13730)

---

## 🔒 Security & Reliability

- **Security:** Strengthened API key WS auth behavior and safer
serverUrl forwarding in gateway-related auth paths. (#13824)
- **Reliability:** Reduced runtime stalls by improving gateway
stop/interrupt and approval-state routing behavior. (#13815, #13863,
#13873)
- **Reliability:** Added defensive guards for malformed tool manifests
and non-string content edge cases. (#13856, #13753)

---

## 👥 Contributors

**101 merged PRs** from **13 contributors** across **107 commits**.

### Community Contributors

- @arvinxx - Runtime, gateway, and execution reliability improvements
- @Innei - Navigation, workflow UX, and desktop/CLI refinements
- @rdmclin2 - Sidebar, recents, and channel behavior updates
- @ONLY-yours - Tooling/runtime fixes and model execution compatibility
- @tjx666 - Model support and release/tooling maintenance
- @nekomeowww - Memory and search-path stability fixes
- @cy948 - CLI indexing and command flow fixes
- @octo-patch - Local system runtime edge-case fixes
- @djthread - Desktop runtime request reliability improvements
- @rivertwilight - Documentation and changelog updates
- @sudongyuer - Subscription/mobile support improvements
- @Zhouguanyang - Provider/model configuration correctness fixes
- @lobehubbot - Translation and maintenance automation support

---

**Full Changelog**: v2.1.49...v2.1.50
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