feat(agent-runtime): pass metadata through createThread/ensureThread/createRun#5949
feat(agent-runtime): pass metadata through createThread/ensureThread/createRun#5949strommmm wants to merge 2 commits into
Conversation
…createRun 打通业务方调 createRun 时 input.metadata 到 AgentStore.createThread 的全链路 透传。chair-sandbox-ai-use 多 agent 路径依赖此能力把 agentName 写入新建 thread 的 metadata,供后续 resume 时按 thread.metadata 读 agentName。 resume 场景下(threadId 已存在),ensureThread 不覆盖原 thread 的 metadata (保持一致性)。 5 个 TDD case 覆盖:createThread 写入 / createThread 默认空 metadata / syncRun 自动建 thread 带 metadata / syncRun resume 不覆盖 / asyncRun 自动 建 thread 带 metadata。 类型新增:CreateThreadOptions、EnsureThreadOptions(位于 @eggjs/tegg-types 的 agent-runtime 子模块),随原 export * 自动导出,无需手动加 index。
📝 WalkthroughWalkthroughAgentRuntime now supports optional metadata at thread creation time via a new ChangesThread Metadata Support
Sequence DiagramsequenceDiagram
participant Caller
participant AgentRuntime
participant AgentStore
participant ThreadStorage
Caller->>AgentRuntime: createThread(metadata)
AgentRuntime->>AgentStore: createThread(metadata)
AgentStore->>ThreadStorage: persist thread with metadata
ThreadStorage-->>AgentStore: thread created
AgentStore-->>AgentRuntime: ThreadObject
AgentRuntime-->>Caller: ThreadObject with metadata
Caller->>AgentRuntime: syncRun(threadId, runMetadata)
AgentRuntime->>AgentStore: createRun(runMetadata)
AgentStore->>ThreadStorage: persist run, do not mutate thread metadata
ThreadStorage-->>AgentStore: run created
AgentStore-->>AgentRuntime: RunResult with runMetadata
AgentRuntime-->>Caller: RunResult (thread metadata unchanged)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #5949 +/- ##
=======================================
Coverage 85.21% 85.21%
=======================================
Files 669 669
Lines 19304 19304
Branches 3787 3787
=======================================
Hits 16449 16449
Misses 2463 2463
Partials 392 392 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends the agent runtime thread-creation API to allow attaching persistent metadata to a newly created thread, and adds tests to ensure run metadata is not accidentally copied into thread metadata.
Changes:
- Add
CreateThreadOptions(withmetadata) to the agent-runtime type definitions. - Update
AgentRuntime.createThread()to accept optional metadata and forward it to the store. - Add a new Vitest suite covering thread metadata persistence and “no run→thread metadata copying” behavior for sync/async/stream runs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tegg/core/types/src/agent-runtime/AgentRuntime.ts | Introduces CreateThreadOptions type and documents intended metadata semantics. |
| tegg/core/agent-runtime/src/AgentRuntime.ts | Extends createThread() to accept options and pass metadata into store.createThread(). |
| tegg/core/agent-runtime/test/AgentRuntime.metadata.test.ts | Adds tests for thread metadata persistence and ensures run metadata doesn’t mutate/copy to thread metadata. |
| /** | ||
| * Options for {@link AgentRuntime.createThread}. | ||
| * | ||
| * `metadata` is forwarded verbatim to {@link AgentStore.createThread} so callers | ||
| * can persist additional business semantics on the thread record (e.g. the | ||
| * resolved agent name, owning sandbox id, trace id). It is stored once at | ||
| * creation time and never overwritten by subsequent runs on the same thread. | ||
| */ |
| end(): void { | ||
| this.closed = true; | ||
| } | ||
|
|
||
| onClose(): void { | ||
| /* noop */ | ||
| } |
There was a problem hiding this comment.
Code Review
This pull request introduces the ability to provide metadata when creating a thread in the AgentRuntime. It adds the CreateThreadOptions interface, updates the createThread method to accept these options, and ensures that metadata is correctly persisted to the store. Additionally, it includes a new test suite to verify metadata handling across various run types (sync, async, and stream) and confirms that run-specific metadata does not overwrite thread metadata. I have no feedback to provide.
|
eggjs/tegg 也要 pick 下。 |
createThread support params to set metadata
Summary by CodeRabbit
New Features
Tests