RouteKitAI 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- routekitai/__init__.py +53 -0
- routekitai/cli/__init__.py +18 -0
- routekitai/cli/main.py +40 -0
- routekitai/cli/replay.py +80 -0
- routekitai/cli/run.py +95 -0
- routekitai/cli/serve.py +966 -0
- routekitai/cli/test_agent.py +178 -0
- routekitai/cli/trace.py +209 -0
- routekitai/cli/trace_analyze.py +120 -0
- routekitai/cli/trace_search.py +126 -0
- routekitai/core/__init__.py +58 -0
- routekitai/core/agent.py +325 -0
- routekitai/core/errors.py +49 -0
- routekitai/core/hooks.py +174 -0
- routekitai/core/memory.py +54 -0
- routekitai/core/message.py +132 -0
- routekitai/core/model.py +91 -0
- routekitai/core/policies.py +373 -0
- routekitai/core/policy.py +85 -0
- routekitai/core/policy_adapter.py +133 -0
- routekitai/core/runtime.py +1403 -0
- routekitai/core/tool.py +148 -0
- routekitai/core/tools.py +180 -0
- routekitai/evals/__init__.py +13 -0
- routekitai/evals/dataset.py +75 -0
- routekitai/evals/metrics.py +101 -0
- routekitai/evals/runner.py +184 -0
- routekitai/graphs/__init__.py +12 -0
- routekitai/graphs/executors.py +457 -0
- routekitai/graphs/graph.py +164 -0
- routekitai/memory/__init__.py +13 -0
- routekitai/memory/episodic.py +242 -0
- routekitai/memory/kv.py +34 -0
- routekitai/memory/retrieval.py +192 -0
- routekitai/memory/vector.py +700 -0
- routekitai/memory/working.py +66 -0
- routekitai/message.py +29 -0
- routekitai/model.py +48 -0
- routekitai/observability/__init__.py +21 -0
- routekitai/observability/analyzer.py +314 -0
- routekitai/observability/exporters/__init__.py +10 -0
- routekitai/observability/exporters/base.py +30 -0
- routekitai/observability/exporters/jsonl.py +81 -0
- routekitai/observability/exporters/otel.py +119 -0
- routekitai/observability/spans.py +111 -0
- routekitai/observability/streaming.py +117 -0
- routekitai/observability/trace.py +144 -0
- routekitai/providers/__init__.py +9 -0
- routekitai/providers/anthropic.py +227 -0
- routekitai/providers/azure_openai.py +243 -0
- routekitai/providers/local.py +196 -0
- routekitai/providers/openai.py +321 -0
- routekitai/py.typed +0 -0
- routekitai/sandbox/__init__.py +12 -0
- routekitai/sandbox/filesystem.py +131 -0
- routekitai/sandbox/network.py +142 -0
- routekitai/sandbox/permissions.py +70 -0
- routekitai/tool.py +33 -0
- routekitai-0.1.0.dist-info/METADATA +328 -0
- routekitai-0.1.0.dist-info/RECORD +64 -0
- routekitai-0.1.0.dist-info/WHEEL +5 -0
- routekitai-0.1.0.dist-info/entry_points.txt +2 -0
- routekitai-0.1.0.dist-info/licenses/LICENSE +21 -0
- routekitai-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Adapter to bridge new Policy system with Runtime's Policy interface."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import uuid
|
|
6
|
+
from typing import TYPE_CHECKING, Any
|
|
7
|
+
|
|
8
|
+
from routekitai.core.message import Message
|
|
9
|
+
from routekitai.core.policy import Final, ModelAction, Parallel, Policy, ToolAction
|
|
10
|
+
from routekitai.core.runtime import Policy as RuntimePolicy
|
|
11
|
+
from routekitai.core.runtime import Step
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from routekitai.core.agent import Agent
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PolicyAdapter(RuntimePolicy):
|
|
18
|
+
"""Adapter to use new Action-based Policy with Runtime's Step-based interface."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, policy: Policy) -> None:
|
|
21
|
+
"""Initialize adapter with Action-based policy.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
policy: Action-based policy to adapt
|
|
25
|
+
"""
|
|
26
|
+
self.policy = policy
|
|
27
|
+
self.state: dict[str, Any] = {}
|
|
28
|
+
|
|
29
|
+
async def next_steps(
|
|
30
|
+
self,
|
|
31
|
+
agent: Agent,
|
|
32
|
+
messages: list[Message],
|
|
33
|
+
state: dict[str, Any],
|
|
34
|
+
) -> list[Step]:
|
|
35
|
+
"""Convert Action-based policy to Step-based interface.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
agent: Agent instance
|
|
39
|
+
messages: Current messages
|
|
40
|
+
state: Current state
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
List of steps
|
|
44
|
+
"""
|
|
45
|
+
# Update policy state
|
|
46
|
+
self.state = {
|
|
47
|
+
"agent": agent,
|
|
48
|
+
"messages": messages,
|
|
49
|
+
"tools": agent.tools,
|
|
50
|
+
"memory": agent.memory, # Include memory in state
|
|
51
|
+
"runtime": state.get("runtime"), # Pass runtime to policy for sub-agent execution
|
|
52
|
+
**state,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Get actions from policy
|
|
56
|
+
actions = await self.policy.plan(self.state)
|
|
57
|
+
|
|
58
|
+
# Convert actions to steps
|
|
59
|
+
steps = []
|
|
60
|
+
for action in actions:
|
|
61
|
+
if isinstance(action, ModelAction):
|
|
62
|
+
# Check for special "DELEGATE" message from SupervisorPolicy
|
|
63
|
+
if action.messages and action.messages[0].content.startswith("DELEGATE:"):
|
|
64
|
+
parts = action.messages[0].content.split(":", 2)
|
|
65
|
+
if len(parts) == 3:
|
|
66
|
+
subagent_name = parts[1]
|
|
67
|
+
subagent_prompt = parts[2]
|
|
68
|
+
steps.append(
|
|
69
|
+
Step(
|
|
70
|
+
step_id=str(uuid.uuid4()),
|
|
71
|
+
step_type="subagent_call",
|
|
72
|
+
input_data={
|
|
73
|
+
"agent_name": subagent_name,
|
|
74
|
+
"prompt": subagent_prompt,
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
else:
|
|
79
|
+
# Fallback if format is unexpected
|
|
80
|
+
steps.append(
|
|
81
|
+
Step(
|
|
82
|
+
step_id=str(uuid.uuid4()),
|
|
83
|
+
step_type="model_call",
|
|
84
|
+
input_data={
|
|
85
|
+
"messages": action.messages
|
|
86
|
+
or [Message.user(action.prompt or "")]
|
|
87
|
+
},
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
else:
|
|
91
|
+
# Use messages directly if available, otherwise create from prompt
|
|
92
|
+
step_messages = (
|
|
93
|
+
action.messages if action.messages else [Message.user(action.prompt or "")]
|
|
94
|
+
)
|
|
95
|
+
steps.append(
|
|
96
|
+
Step(
|
|
97
|
+
step_id=str(uuid.uuid4()),
|
|
98
|
+
step_type="model_call",
|
|
99
|
+
input_data={"messages": step_messages},
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
elif isinstance(action, ToolAction):
|
|
103
|
+
steps.append(
|
|
104
|
+
Step(
|
|
105
|
+
step_id=str(uuid.uuid4()),
|
|
106
|
+
step_type="tool_call",
|
|
107
|
+
input_data={
|
|
108
|
+
"tool_name": action.tool_name,
|
|
109
|
+
"tool_args": action.tool_input,
|
|
110
|
+
},
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
elif isinstance(action, Parallel):
|
|
114
|
+
# Create parallel tool call steps
|
|
115
|
+
for sub_action in action.actions:
|
|
116
|
+
# Only handle ToolAction in parallel (other actions not supported yet)
|
|
117
|
+
if isinstance(sub_action, ToolAction):
|
|
118
|
+
steps.append(
|
|
119
|
+
Step(
|
|
120
|
+
step_id=str(uuid.uuid4()),
|
|
121
|
+
step_type="tool_call",
|
|
122
|
+
input_data={
|
|
123
|
+
"tool_name": sub_action.tool_name,
|
|
124
|
+
"tool_args": sub_action.tool_input,
|
|
125
|
+
},
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
# Other action types in parallel not yet supported
|
|
129
|
+
elif isinstance(action, Final):
|
|
130
|
+
# Final action - return empty to signal completion
|
|
131
|
+
return []
|
|
132
|
+
|
|
133
|
+
return steps
|