fix: resolve Letta agent-not-found error and LLM fallback - #3
Open
Spark-Huang wants to merge 1 commit into
Open
Conversation
Key fixes:
1. Fix stale agent ID causing 'agent-not-found' 429 error
- Improved error detection with isAgentNotFoundError()
- Better logging when stale agents are detected and cleared
- Proper fallback to direct LLM when agent creation fails
2. Fix LLM fallback - no longer use Letta API as OpenAI-compatible endpoint
- The Letta /v1/chat/completions endpoint requires an agent_id
and is NOT a standard OpenAI-compatible endpoint
- Created /api/llm/generate route (Node.js runtime) that uses
z-ai-web-dev-sdk for direct LLM calls
- This replaces the broken LLM_API_BASE/LLM_API_KEY approach
3. Fix Letta agent creation
- Use openai/gpt-4o-mini (available model) instead of
openai-proxy/gpt-4.1-mini (not registered in Letta)
- Fix agent creation API format (use 'model' field, not deprecated 'llm_config')
- Fix message response parsing for new Letta API format
4. Fix streaming API
- Use stream_steps instead of stream_tokens (which requires streaming=true)
5. Add type declarations for reicon-react
6. Update wrangler.toml and test files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
1. 修复 Letta agent-not-found 429 错误
isAgentNotFoundError())2. 修复 LLM fallback
/v1/chat/completions端点不是标准的 OpenAI 兼容端点,它需要 agent_id/api/llm/generate路由(Node.js runtime),使用 z-ai-web-dev-sdk 进行直接 LLM 调用LLM_API_BASE/LLM_API_KEY方案3. 修复 Letta agent 创建
openai/gpt-4o-mini(可用模型)替代openai-proxy/gpt-4.1-mini(未在 Letta 注册)model字段,而非已废弃的llm_config)4. 修复 streaming API
stream_steps替代stream_tokens(后者需要streaming=true)5. 其他修复
测试结果
✅ 登录成功
✅ Stale agent 检测和清理
✅ 新 agent 创建
✅ 内容生成(LinkedIn 平台)
✅ Agent 聊天
✅ LLM fallback(z-ai-web-dev-sdk)