chore: initialize project repository
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
|
||||
from app.core.contracts import AgentDefinition, CoreResult, RequestContext
|
||||
from app.core.errors import RecoverableAgentError
|
||||
from app.service.agent.base import BaseAgent
|
||||
from app.service.agent.factory import AgentFactory
|
||||
from app.service.tool_executor import ToolExecutor, ToolRegistry
|
||||
|
||||
|
||||
class DemoAgent(BaseAgent):
|
||||
async def handle(self, request, context):
|
||||
return CoreResult(text="ok")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_agent_without_tool_dependency_fails_closed(governance):
|
||||
definition = AgentDefinition(agent_type="demo", version="1", allowed_roles=("customer",),
|
||||
allowed_portals=("api",))
|
||||
agent = DemoAgent(definition)
|
||||
with pytest.raises(RecoverableAgentError, match="工具执行器"):
|
||||
await agent.call_tool("unknown", {}, intent="general",
|
||||
context=RequestContext(user_id="1", trace_id="t"))
|
||||
|
||||
|
||||
def test_factory_injects_tool_executor(governance):
|
||||
definition = AgentDefinition(agent_type="demo", version="1", allowed_roles=("customer",),
|
||||
allowed_portals=("api",))
|
||||
tool_executor = ToolExecutor(ToolRegistry())
|
||||
factory = AgentFactory(governance, tool_executor=tool_executor)
|
||||
factory.register(definition, lambda _: DemoAgent(definition))
|
||||
context = RequestContext(user_id="1", trace_id="t", roles=("customer",),
|
||||
permissions=("agent:run",))
|
||||
agent = factory.create("demo", context)
|
||||
assert agent._tool_executor is tool_executor
|
||||
Reference in New Issue
Block a user