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.
Files changed (64) hide show
  1. routekitai/__init__.py +53 -0
  2. routekitai/cli/__init__.py +18 -0
  3. routekitai/cli/main.py +40 -0
  4. routekitai/cli/replay.py +80 -0
  5. routekitai/cli/run.py +95 -0
  6. routekitai/cli/serve.py +966 -0
  7. routekitai/cli/test_agent.py +178 -0
  8. routekitai/cli/trace.py +209 -0
  9. routekitai/cli/trace_analyze.py +120 -0
  10. routekitai/cli/trace_search.py +126 -0
  11. routekitai/core/__init__.py +58 -0
  12. routekitai/core/agent.py +325 -0
  13. routekitai/core/errors.py +49 -0
  14. routekitai/core/hooks.py +174 -0
  15. routekitai/core/memory.py +54 -0
  16. routekitai/core/message.py +132 -0
  17. routekitai/core/model.py +91 -0
  18. routekitai/core/policies.py +373 -0
  19. routekitai/core/policy.py +85 -0
  20. routekitai/core/policy_adapter.py +133 -0
  21. routekitai/core/runtime.py +1403 -0
  22. routekitai/core/tool.py +148 -0
  23. routekitai/core/tools.py +180 -0
  24. routekitai/evals/__init__.py +13 -0
  25. routekitai/evals/dataset.py +75 -0
  26. routekitai/evals/metrics.py +101 -0
  27. routekitai/evals/runner.py +184 -0
  28. routekitai/graphs/__init__.py +12 -0
  29. routekitai/graphs/executors.py +457 -0
  30. routekitai/graphs/graph.py +164 -0
  31. routekitai/memory/__init__.py +13 -0
  32. routekitai/memory/episodic.py +242 -0
  33. routekitai/memory/kv.py +34 -0
  34. routekitai/memory/retrieval.py +192 -0
  35. routekitai/memory/vector.py +700 -0
  36. routekitai/memory/working.py +66 -0
  37. routekitai/message.py +29 -0
  38. routekitai/model.py +48 -0
  39. routekitai/observability/__init__.py +21 -0
  40. routekitai/observability/analyzer.py +314 -0
  41. routekitai/observability/exporters/__init__.py +10 -0
  42. routekitai/observability/exporters/base.py +30 -0
  43. routekitai/observability/exporters/jsonl.py +81 -0
  44. routekitai/observability/exporters/otel.py +119 -0
  45. routekitai/observability/spans.py +111 -0
  46. routekitai/observability/streaming.py +117 -0
  47. routekitai/observability/trace.py +144 -0
  48. routekitai/providers/__init__.py +9 -0
  49. routekitai/providers/anthropic.py +227 -0
  50. routekitai/providers/azure_openai.py +243 -0
  51. routekitai/providers/local.py +196 -0
  52. routekitai/providers/openai.py +321 -0
  53. routekitai/py.typed +0 -0
  54. routekitai/sandbox/__init__.py +12 -0
  55. routekitai/sandbox/filesystem.py +131 -0
  56. routekitai/sandbox/network.py +142 -0
  57. routekitai/sandbox/permissions.py +70 -0
  58. routekitai/tool.py +33 -0
  59. routekitai-0.1.0.dist-info/METADATA +328 -0
  60. routekitai-0.1.0.dist-info/RECORD +64 -0
  61. routekitai-0.1.0.dist-info/WHEEL +5 -0
  62. routekitai-0.1.0.dist-info/entry_points.txt +2 -0
  63. routekitai-0.1.0.dist-info/licenses/LICENSE +21 -0
  64. 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