Skip to content

Feat/agent runner plugin#2210

Draft
huanghuoguoguo wants to merge 33 commits into
masterfrom
feat/agent-runner-plugin
Draft

Feat/agent runner plugin#2210
huanghuoguoguo wants to merge 33 commits into
masterfrom
feat/agent-runner-plugin

Conversation

@huanghuoguoguo
Copy link
Copy Markdown
Collaborator

@huanghuoguoguo huanghuoguoguo commented May 17, 2026

状态 / Status

测试中,请勿合并。

该 PR 是 LangBot 侧 Agent Runner Plugin 联调入口,当前需要和 Plugin SDK PR 以及两个 runner 仓库一起测试。

关联 PR / Related PR

关联测试仓库 / Related Testing Repositories

当前测试重点 / Current Test Focus

  • Pipeline AI 配置中 AgentRunner 参数是否能正确渲染、填写、保存。
  • Local Agent Runner 的 Debug Chat 是否保持原有行为并能正常返回。
  • LangRAG 知识库创建、文档上传、检索和 local-agent RAG 对话是否走通。
  • MCP stdio server、工具发现和 local-agent tool calling 是否走通。
  • 前端控制台不应出现阻断性 React/runtime error。

概述 / Overview

请在此部分填写你实现/解决/优化的内容:
Summary of what you implemented/solved/optimized:

更改前后对比截图 / Screenshots

请在此部分粘贴更改前后对比截图(可以是界面截图、控制台输出、对话截图等):
Please paste the screenshots of changes before and after here (can be interface screenshots, console output, conversation screenshots, etc.):

修改前 / Before:

修改后 / After:

检查清单 / Checklist

PR 作者完成 / For PR author

请在方括号间写x以打勾 / Please tick the box with x

  • 阅读仓库贡献指引了吗? / Have you read the contribution guide?
  • 与项目所有者沟通过了吗? / Have you communicated with the project maintainer?
  • 我确定已自行测试所作的更改,确保功能符合预期。 / I have tested the changes and ensured they work as expected.

项目维护者完成 / For project maintainer

  • 相关 issues 链接了吗? / Have you linked the related issues?
  • 配置项写好了吗?迁移写好了吗?生效了吗? / Have you written the configuration items? Have you written the migration? Has it taken effect?
  • 依赖加到 pyproject.toml 和 core/bootutils/deps.py 了吗 / Have you added the dependencies to pyproject.toml and core/bootutils/deps.py?
  • 文档编写了吗? / Have you written the documentation?

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. eh: Feature enhance: 新功能添加 / add new features External Plugin 插件问题或新增插件 / Issues on plugin itself m: Lifecycle 启动/关闭流程 / Bootstrap & application life cycle m: Plugins 插件加载及管理模块 / Plugins loading and management labels May 17, 2026
Comment thread tests/unit_tests/agent/test_handler_auth.py Fixed
Comment thread tests/unit_tests/agent/test_handler_auth.py Fixed
Comment thread tests/unit_tests/agent/test_handler_auth.py Fixed
Comment thread tests/unit_tests/agent/test_handler_auth.py Fixed
Comment thread tests/unit_tests/agent/test_handler_auth.py Fixed
Comment thread tests/unit_tests/agent/test_handler_auth.py Fixed
Comment thread tests/unit_tests/agent/test_handler_auth.py Fixed
Comment thread tests/unit_tests/agent/test_session_registry.py Fixed
Comment thread tests/unit_tests/agent/test_session_registry.py Fixed
Comment thread tests/unit_tests/agent/test_session_registry.py Fixed
Comment thread src/langbot/pkg/agent/runner/resource_builder.py Fixed
Comment thread src/langbot/pkg/agent/runner/resource_builder.py Fixed
Comment thread src/langbot/pkg/agent/runner/resource_builder.py Fixed
Comment thread src/langbot/pkg/agent/runner/result_normalizer.py Fixed
RockChinQ and others added 15 commits May 17, 2026 11:05
Phase 0 integration complete - verified minimal loop with local-agent stub runner.

Changes:
- Add AgentRunOrchestrator for plugin-based agent execution
- Add AgentResultNormalizer for Protocol v1 result conversion
- Add AgentRunnerDescriptor for runner ID parsing (plugin:author/name/runner)
- Update chat handler to use new orchestrator instead of direct runner lookup
- Add plugin handler methods for list_agent_runners and run_agent
- Add connector methods for AgentRunner protocol forwarding
- Update pipeline API to include runner options in metadata
- Add integration docs and implementation plan

Integration verified:
- Runner: plugin:langbot/local-agent/default
- Input: "你好"
- Output: [stub] Echo: 你好
- Date: 2026-05-10 10:09

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add pre-computed _authorized_ids (frozenset) at session registration for O(1) lookup
- Refactor is_resource_allowed() from linear search to set membership check
- Add thread-safe locking to get_session_registry() singleton
- Cache _session_registry and _state_store references in orchestrator __init__
- Add asyncio.gather() for parallel resource building in AgentResourceBuilder
- Create shared test fixtures in tests/unit_tests/agent/conftest.py
- Update test files to import from shared conftest.py

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add DEPRECATED docstring to all legacy runners in pkg/provider/runners/
- Mark migration target for each runner (local-agent, dify, n8n, coze, dashscope, langflow, tbox)
- Add PROGRESS.md to track agent-runner-pluginization implementation status
- Remove completed PHASE0_INTEGRATION_RECORD.md
…zation

- Add invoke_rerank action handler in plugin handler
- Validate rerank model access via run session
- Cap documents at 64 for API limit
- Return sorted results by relevance score
Add unified tool lookup method that searches both plugin and MCP loaders.
Also add _get_tool method to MCPLoader for consistency with PluginToolLoader.
Add EventLog and Transcript persistence entities for storing auditable
event facts and conversation history projection. Implement event-first
AgentRunContext builder that produces Protocol v1 compliant context
payloads with required fields: event, delivery, context (ContextAccess).

Key changes:
- EventLog ORM: auditable event records with indexes
- Transcript ORM: conversation history projection with composite indexes
- AgentRunContextBuilder: Protocol v1 payload with delivery, context, bootstrap
- EventLogStore/TranscriptStore: async stores for fact sources
- Host action handlers: HISTORY_PAGE, HISTORY_SEARCH, EVENT_GET, EVENT_PAGE
- Context validation: build_context output validates via SDK AgentRunContext
- Alembic migration for event_log and transcript tables
- Alembic env.py imports all ORM models for autogenerate discovery

Legacy compatibility: max-round messages go into bootstrap.messages and
compatibility.legacy_messages, not top-level messages field.
- run_from_query() now delegates to run(event, binding) instead of maintaining
  a separate legacy execution path
- Pipeline Query is converted to AgentEventEnvelope via PipelineCompatAdapter
- Pipeline config is converted to AgentBinding with StatePolicy
- bound_plugins authorization preserved from Pipeline
- Legacy compatibility fields preserved:
  - query_id → context.runtime.query_id → session registry
  - prompt → context.compatibility.extra.prompt (not top-level)
  - params → context.compatibility.extra.params (with proper filtering)
  - max-round → bootstrap.messages and compatibility.legacy_messages
- Pipeline path gains event-first host capabilities:
  - EventLog and Transcript writing
  - ArtifactStore registration
  - PersistentStateStore for state.updated
- Removed legacy handlers:
  - _handle_artifact_created_query() (replaced by _handle_artifact_created)
  - _handle_state_updated() (replaced by _handle_state_updated_event)

This change unifies the execution path while preserving backward compatibility
for Pipeline-based runners. EventGateway is not implemented in this branch;
only the event-first entry point is reserved.
def mock_session_registry(self):
"""Create a fresh session registry for testing."""
# Reset global registry
import langbot.pkg.agent.runner.session_registry as reg
@pytest.fixture
def session_registry(self):
"""Create a fresh session registry for testing."""
import langbot.pkg.agent.runner.session_registry as reg
Comment on lines +18 to +36
from langbot.pkg.entity.persistence import (
agent_runner_state,
apikey,
artifact,
bot,
bstorage,
event_log,
mcp,
metadata,
model,
monitoring,
pipeline,
plugin,
rag,
transcript,
user,
vector,
webhook,
)
from sqlalchemy.orm import sessionmaker

from ...entity.persistence.event_log import EventLog
from ...entity.persistence.transcript import Transcript
Comment on lines +10 to +16
from langbot_plugin.api.entities.builtin.agent_runner.event import (
AgentEventContext,
ConversationContext,
ActorContext,
SubjectContext,
RawEventRef,
)
Comment thread src/langbot/pkg/agent/runner/persistent_state_store.py Fixed
Comment thread src/langbot/pkg/agent/runner/persistent_state_store.py Fixed
Comment thread src/langbot/pkg/agent/runner/pipeline_adapter.py Fixed
Comment thread src/langbot/pkg/agent/runner/pipeline_adapter.py Fixed
Comment thread tests/unit_tests/agent/test_artifact_store.py Fixed
],
)

messages = [message async for message in orchestrator.run_from_query(query)]
"another_param": 123,
}

messages = [message async for message in orchestrator.run_from_query(query)]
"_pipeline_bound_plugins": ["plugin1"],
}

messages = [message async for message in orchestrator.run_from_query(query)]
"credential": "secret000",
}

messages = [message async for message in orchestrator.run_from_query(query)]
"a_lambda": lambda x: x, # function is not JSON-serializable
}

messages = [message async for message in orchestrator.run_from_query(query)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eh: Feature enhance: 新功能添加 / add new features External Plugin 插件问题或新增插件 / Issues on plugin itself m: Lifecycle 启动/关闭流程 / Bootstrap & application life cycle m: Plugins 插件加载及管理模块 / Plugins loading and management size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants