feat(agentscope): add memory system and automation job support
- Add consumer_registry and pipeline_registry for runtime orchestration - Add Visibility schema for message filtering - Add PipelineSpec for agent pipeline configuration - Add automation job models and configuration - Remove memory_prompt.py (consolidated into memory system) - Update runtime components: context_loader, context_service, orchestrator, runner, tasks - Update toolkit: tool_config, tool_middleware, custom tools (calendar, user_lookup) - Add auth_helpers and calendar_domain utilities - Add system_agents.yaml configuration
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from schemas.agent.consumer_registry import AgentConsumerBinding, ConsumerRegistry
|
||||
from schemas.agent.pipeline_spec import (
|
||||
ContextPolicy,
|
||||
ExecutorKind,
|
||||
PipelineSpec,
|
||||
StageSpec,
|
||||
)
|
||||
|
||||
|
||||
def test_consumer_registry_rejects_duplicate_bits() -> None:
|
||||
with pytest.raises(ValueError, match="duplicate visibility bit"):
|
||||
ConsumerRegistry(
|
||||
bindings=[
|
||||
AgentConsumerBinding(agent_type="router", bit=16),
|
||||
AgentConsumerBinding(agent_type="worker", bit=16),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_pipeline_spec_requires_non_empty_stages() -> None:
|
||||
with pytest.raises(ValueError, match="at least 1 item"):
|
||||
PipelineSpec(mode="worker", stages=[])
|
||||
|
||||
|
||||
def test_stage_spec_normalizes_stage_name() -> None:
|
||||
spec = StageSpec(
|
||||
stage_name=" Worker ",
|
||||
executor_kind=ExecutorKind.REACT,
|
||||
default_visibility_mask=1,
|
||||
context_policy=ContextPolicy(consumer_agent_type="worker", count=20),
|
||||
)
|
||||
|
||||
assert spec.stage_name == "worker"
|
||||
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from schemas.agent.system_agent import SystemAgentLLMConfig
|
||||
|
||||
|
||||
def test_system_agent_llm_config_normalizes_enabled_tools_aliases() -> None:
|
||||
config = SystemAgentLLMConfig.model_validate(
|
||||
{
|
||||
"enabled_tools": [
|
||||
"calendar.write",
|
||||
"calendar_write",
|
||||
"user.lookup",
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
assert [tool.value for tool in config.enabled_tools] == [
|
||||
"calendar.write",
|
||||
"user.lookup",
|
||||
]
|
||||
|
||||
|
||||
def test_system_agent_llm_config_rejects_unknown_enabled_tool() -> None:
|
||||
with pytest.raises(ValueError, match="unknown enabled tool"):
|
||||
SystemAgentLLMConfig.model_validate(
|
||||
{
|
||||
"enabled_tools": ["calendar.remove"],
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from schemas.agent.visibility import VisibilityMask, bit_mask
|
||||
|
||||
|
||||
def test_visibility_mask_from_bits_and_contains() -> None:
|
||||
mask = VisibilityMask.from_bits(bits=[0, 16, 18])
|
||||
|
||||
assert mask.contains(bit=0) is True
|
||||
assert mask.contains(bit=16) is True
|
||||
assert mask.contains(bit=17) is False
|
||||
|
||||
|
||||
def test_visibility_mask_rejects_out_of_range_bit() -> None:
|
||||
with pytest.raises(ValueError, match="range"):
|
||||
VisibilityMask.from_bits(bits=[64])
|
||||
|
||||
|
||||
def test_bit_mask_builds_single_bit_integer() -> None:
|
||||
assert bit_mask(bit=0) == 1
|
||||
assert bit_mask(bit=16) == (1 << 16)
|
||||
@@ -0,0 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from schemas.automation.config import AutomationJobConfig, default_memory_job_config
|
||||
|
||||
|
||||
def test_default_memory_job_config_has_expected_defaults() -> None:
|
||||
config = default_memory_job_config()
|
||||
|
||||
assert config.agent_type.value == "memory"
|
||||
assert config.model_code == "qwen3.5-flash"
|
||||
assert config.context.source.value == "latest_chat"
|
||||
|
||||
|
||||
def test_automation_job_config_rejects_non_flash_model() -> None:
|
||||
with pytest.raises(ValueError, match="model_code must be qwen3.5-flash"):
|
||||
AutomationJobConfig.model_validate(
|
||||
{
|
||||
"agent_type": "memory",
|
||||
"model_code": "qwen-plus",
|
||||
"enabled_tools": ["calendar.read"],
|
||||
"input_template": "x",
|
||||
"context": {
|
||||
"source": "latest_chat",
|
||||
"window_mode": "day",
|
||||
"window_count": 2,
|
||||
},
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user