Skip to content

fix: resolve Letta agent-not-found error and LLM fallback - #3

Open
Spark-Huang wants to merge 1 commit into
joeymilano:mainfrom
Spark-Huang:fix/letta-agent-not-found
Open

fix: resolve Letta agent-not-found error and LLM fallback#3
Spark-Huang wants to merge 1 commit into
joeymilano:mainfrom
Spark-Huang:fix/letta-agent-not-found

Conversation

@Spark-Huang

Copy link
Copy Markdown

修复内容

1. 修复 Letta agent-not-found 429 错误

  • 改进了 stale agent ID 的检测逻辑(isAgentNotFoundError()
  • 当检测到失效 agent 时,自动清理并重新创建
  • 添加了详细的日志记录

2. 修复 LLM fallback

  • 关键修复:Letta 的 /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 注册)
  • 修复 agent 创建 API 格式(使用 model 字段,而非已废弃的 llm_config
  • 修复消息响应解析以适配新 Letta API 格式

4. 修复 streaming API

  • 使用 stream_steps 替代 stream_tokens(后者需要 streaming=true

5. 其他修复

  • 添加 reicon-react 类型声明
  • 更新 wrangler.toml 和测试文件

测试结果

✅ 登录成功
✅ Stale agent 检测和清理
✅ 新 agent 创建
✅ 内容生成(LinkedIn 平台)
✅ Agent 聊天
✅ LLM fallback(z-ai-web-dev-sdk)

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
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