agenkit 0.91.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.
- agenkit/README.md +398 -0
- agenkit/__init__.py +52 -0
- agenkit/_llm_protocol.py +293 -0
- agenkit/adapters/__init__.py +10 -0
- agenkit/adapters/llm/__init__.py +112 -0
- agenkit/adapters/llm/anthropic.py +268 -0
- agenkit/adapters/llm/base.py +247 -0
- agenkit/adapters/llm/bedrock.py +398 -0
- agenkit/adapters/llm/gemini.py +269 -0
- agenkit/adapters/llm/litellm.py +249 -0
- agenkit/adapters/llm/ollama.py +260 -0
- agenkit/adapters/llm/openai.py +256 -0
- agenkit/adapters/llm/openai_compatible.py +418 -0
- agenkit/adapters/llm/service_connectors.py +149 -0
- agenkit/adapters/python/__init__.py +74 -0
- agenkit/adapters/python/codec.py +292 -0
- agenkit/adapters/python/errors.py +150 -0
- agenkit/adapters/python/grpc_server.py +306 -0
- agenkit/adapters/python/grpc_transport.py +757 -0
- agenkit/adapters/python/http_server.py +372 -0
- agenkit/adapters/python/http_transport.py +284 -0
- agenkit/adapters/python/local_agent.py +521 -0
- agenkit/adapters/python/registry.py +205 -0
- agenkit/adapters/python/remote_agent.py +297 -0
- agenkit/adapters/python/transport.py +549 -0
- agenkit/adapters/python/websocket_transport.py +252 -0
- agenkit/agents_md/__init__.py +54 -0
- agenkit/agents_md/integration.py +200 -0
- agenkit/agents_md/parser.py +228 -0
- agenkit/agents_md/types.py +159 -0
- agenkit/agents_md/validator.py +199 -0
- agenkit/auth/__init__.py +48 -0
- agenkit/auth/middleware.py +178 -0
- agenkit/auth/providers.py +140 -0
- agenkit/budget/README.md +202 -0
- agenkit/budget/__init__.py +78 -0
- agenkit/budget/limiter.py +338 -0
- agenkit/budget/models.py +204 -0
- agenkit/budget/optimizer.py +438 -0
- agenkit/budget/reasoning.py +327 -0
- agenkit/budget/tracker.py +412 -0
- agenkit/checkpointing/README.md +471 -0
- agenkit/checkpointing/__init__.py +57 -0
- agenkit/checkpointing/checkpoint.py +196 -0
- agenkit/checkpointing/durable.py +299 -0
- agenkit/checkpointing/manager.py +353 -0
- agenkit/checkpointing/storage.py +297 -0
- agenkit/composition/__init__.py +34 -0
- agenkit/composition/conditional.py +228 -0
- agenkit/composition/fallback.py +74 -0
- agenkit/composition/parallel.py +123 -0
- agenkit/composition/sequential.py +68 -0
- agenkit/evaluation/README.md +652 -0
- agenkit/evaluation/__init__.py +114 -0
- agenkit/evaluation/ab_testing.py +424 -0
- agenkit/evaluation/bayesian_optimizer.py +324 -0
- agenkit/evaluation/benchmarks.py +466 -0
- agenkit/evaluation/context_metrics.py +386 -0
- agenkit/evaluation/core.py +304 -0
- agenkit/evaluation/error_tracker.py +121 -0
- agenkit/evaluation/metrics.py +329 -0
- agenkit/evaluation/optimizer.py +337 -0
- agenkit/evaluation/pattern_benchmarks.py +564 -0
- agenkit/evaluation/prompt_optimizer.py +427 -0
- agenkit/evaluation/quality_metrics.py +420 -0
- agenkit/evaluation/recorder.py +540 -0
- agenkit/evaluation/regression.py +381 -0
- agenkit/infrastructure/__init__.py +73 -0
- agenkit/infrastructure/health.py +446 -0
- agenkit/infrastructure/load_balancer.py +356 -0
- agenkit/infrastructure/retry_enhanced.py +427 -0
- agenkit/interfaces.py +676 -0
- agenkit/introspection.py +82 -0
- agenkit/memory/__init__.py +92 -0
- agenkit/memory/base.py +154 -0
- agenkit/memory/endless_memory.py +176 -0
- agenkit/memory/hierarchy_memory.py +455 -0
- agenkit/memory/in_memory.py +181 -0
- agenkit/memory/redis_memory.py +268 -0
- agenkit/memory/strategies/__init__.py +18 -0
- agenkit/memory/strategies/base.py +58 -0
- agenkit/memory/strategies/importance_weighting.py +136 -0
- agenkit/memory/strategies/sliding_window.py +65 -0
- agenkit/memory/strategies/summarization.py +94 -0
- agenkit/memory/vector_memory.py +387 -0
- agenkit/middleware/__init__.py +61 -0
- agenkit/middleware/batching.py +354 -0
- agenkit/middleware/caching.py +361 -0
- agenkit/middleware/circuit_breaker.py +225 -0
- agenkit/middleware/metrics.py +154 -0
- agenkit/middleware/per_user_rate_limiter.py +407 -0
- agenkit/middleware/rate_limiter.py +240 -0
- agenkit/middleware/retry.py +158 -0
- agenkit/middleware/timeout.py +278 -0
- agenkit/observability/__init__.py +48 -0
- agenkit/observability/audit.py +556 -0
- agenkit/observability/error_metrics.py +95 -0
- agenkit/observability/logging.py +185 -0
- agenkit/observability/metrics.py +193 -0
- agenkit/observability/tracing.py +210 -0
- agenkit/patterns/__init__.py +236 -0
- agenkit/patterns/agents_as_tools.py +282 -0
- agenkit/patterns/autonomous.py +246 -0
- agenkit/patterns/collaborative.py +421 -0
- agenkit/patterns/conversational.py +400 -0
- agenkit/patterns/fallback.py +339 -0
- agenkit/patterns/human_in_loop.py +393 -0
- agenkit/patterns/memory.py +740 -0
- agenkit/patterns/multiagent.py +337 -0
- agenkit/patterns/orchestration.py +678 -0
- agenkit/patterns/parallel.py +240 -0
- agenkit/patterns/planning.py +545 -0
- agenkit/patterns/react.py +473 -0
- agenkit/patterns/reasoning_with_tools.py +507 -0
- agenkit/patterns/reflection.py +607 -0
- agenkit/patterns/router.py +420 -0
- agenkit/patterns/sequential.py +140 -0
- agenkit/patterns/supervisor.py +442 -0
- agenkit/patterns/task.py +235 -0
- agenkit/protocols/agui/__init__.py +151 -0
- agenkit/protocols/agui/adapter.py +208 -0
- agenkit/protocols/agui/events.py +378 -0
- agenkit/protocols/agui/multimodal.py +418 -0
- agenkit/protocols/agui/state.py +209 -0
- agenkit/protocols/agui/tools.py +270 -0
- agenkit/protocols/agui/transports/__init__.py +13 -0
- agenkit/protocols/agui/transports/sse.py +180 -0
- agenkit/protocols/agui_simple/__init__.py +85 -0
- agenkit/protocols/agui_simple/adapter.py +363 -0
- agenkit/protocols/agui_simple/events.py +385 -0
- agenkit/protocols/agui_simple/hitl.py +620 -0
- agenkit/protocols/agui_simple/transports/__init__.py +35 -0
- agenkit/protocols/agui_simple/transports/http.py +366 -0
- agenkit/protocols/agui_simple/transports/websocket.py +403 -0
- agenkit/protocols/mcp/__init__.py +53 -0
- agenkit/protocols/mcp/client.py +262 -0
- agenkit/protocols/mcp/server.py +196 -0
- agenkit/protocols/mcp/tool_adapter.py +67 -0
- agenkit/protocols/mcp/types.py +170 -0
- agenkit/reasoning/__init__.py +27 -0
- agenkit/reasoning/artifact.py +54 -0
- agenkit/reasoning/memory.py +108 -0
- agenkit/reasoning/verifier.py +162 -0
- agenkit/routing/__init__.py +22 -0
- agenkit/routing/load_balancer.py +459 -0
- agenkit/routing/semantic_selector.py +456 -0
- agenkit/safety/__init__.py +48 -0
- agenkit/safety/anomaly_detection.py +381 -0
- agenkit/safety/audit.py +437 -0
- agenkit/safety/input_validation.py +312 -0
- agenkit/safety/output_validation.py +335 -0
- agenkit/safety/permissions.py +394 -0
- agenkit/skills/__init__.py +32 -0
- agenkit/skills/agent.py +85 -0
- agenkit/skills/loader.py +197 -0
- agenkit/techniques/__init__.py +24 -0
- agenkit/techniques/compositions/README.md +360 -0
- agenkit/techniques/compositions/__init__.py +75 -0
- agenkit/techniques/compositions/actor_critic_variation.py +353 -0
- agenkit/techniques/compositions/context_optimization.py +211 -0
- agenkit/techniques/compositions/exploration.py +297 -0
- agenkit/techniques/compositions/goal_monitoring.py +244 -0
- agenkit/techniques/compositions/learning_feedback.py +344 -0
- agenkit/techniques/compositions/prioritization.py +273 -0
- agenkit/techniques/compositions/rag.py +180 -0
- agenkit/techniques/compositions/rag_with_citations.py +271 -0
- agenkit/techniques/compositions/simple_human_approval.py +134 -0
- agenkit/techniques/protocols/__init__.py +0 -0
- agenkit/techniques/protocols/a2a/__init__.py +147 -0
- agenkit/techniques/protocols/a2a/adapters/__init__.py +17 -0
- agenkit/techniques/protocols/a2a/adapters/bedrock.py +190 -0
- agenkit/techniques/protocols/a2a/adapters/vertex_ai.py +190 -0
- agenkit/techniques/protocols/a2a/agent.py +318 -0
- agenkit/techniques/protocols/a2a/discovery.py +312 -0
- agenkit/techniques/protocols/a2a/message.py +324 -0
- agenkit/techniques/protocols/a2a/protocol.py +320 -0
- agenkit/techniques/protocols/a2a/server.py +286 -0
- agenkit/techniques/protocols/a2a/transport.py +371 -0
- agenkit/techniques/protocols/mcp/__init__.py +111 -0
- agenkit/techniques/protocols/mcp/adapter.py +193 -0
- agenkit/techniques/protocols/mcp/client.py +236 -0
- agenkit/techniques/protocols/mcp/message.py +226 -0
- agenkit/techniques/protocols/mcp/resources.py +232 -0
- agenkit/techniques/protocols/mcp/schema.py +162 -0
- agenkit/techniques/protocols/mcp/server.py +358 -0
- agenkit/techniques/protocols/mcp/tools.py +246 -0
- agenkit/techniques/protocols/mcp/transports.py +297 -0
- agenkit/techniques/reasoning/__init__.py +47 -0
- agenkit/techniques/reasoning/_llm_call.py +20 -0
- agenkit/techniques/reasoning/chain_of_thought.py +223 -0
- agenkit/techniques/reasoning/graph_of_thought.py +516 -0
- agenkit/techniques/reasoning/least_to_most.py +300 -0
- agenkit/techniques/reasoning/plan_and_solve.py +399 -0
- agenkit/techniques/reasoning/reasoning_graph.py +364 -0
- agenkit/techniques/reasoning/reasoning_tree.py +239 -0
- agenkit/techniques/reasoning/self_consistency.py +369 -0
- agenkit/techniques/reasoning/tree_of_thought.py +447 -0
- agenkit/tests/test_llm_validation.py +140 -0
- agenkit/tools/__init__.py +10 -0
- agenkit/tools/tool_agent.py +155 -0
- agenkit/tools/tool_registry.py +74 -0
- agenkit-0.91.0.dist-info/METADATA +743 -0
- agenkit-0.91.0.dist-info/RECORD +210 -0
- agenkit-0.91.0.dist-info/WHEEL +4 -0
- agenkit-0.91.0.dist-info/licenses/LICENSE +201 -0
- proto/__init__.py +33 -0
- proto/agent.proto +97 -0
- proto/agent_pb2.py +75 -0
- proto/agent_pb2.pyi +249 -0
- proto/agent_pb2_grpc.py +197 -0
agenkit/README.md
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
# Agenkit Python
|
|
2
|
+
|
|
3
|
+
**Production-ready AI agent toolkit for Python 3.10+**
|
|
4
|
+
|
|
5
|
+
The Python implementation of Agenkit provides the reference implementation with the most complete feature set and best developer experience.
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/agenkit/)
|
|
8
|
+
[](https://www.python.org/downloads/)
|
|
9
|
+
[](../../tests/)
|
|
10
|
+
[](https://agenkit.dev)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install agenkit
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Optional Dependencies
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# With LLM adapters
|
|
22
|
+
pip install agenkit[anthropic,openai]
|
|
23
|
+
|
|
24
|
+
# With observability
|
|
25
|
+
pip install agenkit[observability]
|
|
26
|
+
|
|
27
|
+
# Full installation
|
|
28
|
+
pip install agenkit[all]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### Basic Agent
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from agenkit import Agent, Message
|
|
37
|
+
|
|
38
|
+
class EchoAgent(Agent):
|
|
39
|
+
@property
|
|
40
|
+
def name(self) -> str:
|
|
41
|
+
return "echo-agent"
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def capabilities(self) -> list[str]:
|
|
45
|
+
return ["echo", "simple"]
|
|
46
|
+
|
|
47
|
+
async def process(self, message: Message) -> Message:
|
|
48
|
+
return Message(
|
|
49
|
+
role="assistant",
|
|
50
|
+
content=f"Echo: {message.content}"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def introspect(self) -> IntrospectionResult:
|
|
54
|
+
return default_introspection_result(self)
|
|
55
|
+
|
|
56
|
+
# Use it
|
|
57
|
+
agent = EchoAgent()
|
|
58
|
+
response = await agent.process(Message(role="user", content="Hello!"))
|
|
59
|
+
print(response.content) # "Echo: Hello!"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Production-Ready Agent with Resilience
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from agenkit import Agent, Message
|
|
66
|
+
from agenkit.middleware import (
|
|
67
|
+
RetryMiddleware,
|
|
68
|
+
CircuitBreakerMiddleware,
|
|
69
|
+
TimeoutMiddleware
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Create agent
|
|
73
|
+
agent = MyAgent()
|
|
74
|
+
|
|
75
|
+
# Add resilience
|
|
76
|
+
agent = RetryMiddleware(agent, max_retries=3, backoff_factor=2.0)
|
|
77
|
+
agent = CircuitBreakerMiddleware(agent, failure_threshold=5, recovery_timeout=60.0)
|
|
78
|
+
agent = TimeoutMiddleware(agent, timeout=30.0)
|
|
79
|
+
|
|
80
|
+
# Now it's production-ready with automatic retries, circuit breaking, and timeouts
|
|
81
|
+
response = await agent.process(message)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Agent Patterns
|
|
85
|
+
|
|
86
|
+
#### Sequential Pipeline
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from agenkit.patterns import SequentialAgent
|
|
90
|
+
|
|
91
|
+
# Data flows: Agent1 → Agent2 → Agent3
|
|
92
|
+
pipeline = SequentialAgent([
|
|
93
|
+
DataExtractionAgent(),
|
|
94
|
+
AnalysisAgent(),
|
|
95
|
+
ReportGenerationAgent()
|
|
96
|
+
])
|
|
97
|
+
|
|
98
|
+
result = await pipeline.process(message)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Parallel Execution
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from agenkit.patterns import ParallelAgent
|
|
105
|
+
|
|
106
|
+
# Execute multiple agents concurrently
|
|
107
|
+
parallel = ParallelAgent([
|
|
108
|
+
SentimentAnalysisAgent(),
|
|
109
|
+
EntityExtractionAgent(),
|
|
110
|
+
TopicClassificationAgent()
|
|
111
|
+
])
|
|
112
|
+
|
|
113
|
+
result = await parallel.process(message)
|
|
114
|
+
# Results are automatically aggregated
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Conversational Agent
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from agenkit.patterns import ConversationalAgent
|
|
121
|
+
from agenkit.adapters import AnthropicAdapter
|
|
122
|
+
|
|
123
|
+
# Maintains conversation history
|
|
124
|
+
agent = ConversationalAgent(
|
|
125
|
+
llm=AnthropicAdapter(api_key="..."),
|
|
126
|
+
system_prompt="You are a helpful assistant.",
|
|
127
|
+
max_history=10
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
response1 = await agent.process(Message(content="What's the capital of France?"))
|
|
131
|
+
response2 = await agent.process(Message(content="What's its population?"))
|
|
132
|
+
# Agent remembers context from previous messages
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### ReAct (Reasoning + Acting)
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from agenkit.patterns import ReActAgent, Tool
|
|
139
|
+
|
|
140
|
+
class CalculatorTool(Tool):
|
|
141
|
+
def name(self) -> str:
|
|
142
|
+
return "calculator"
|
|
143
|
+
|
|
144
|
+
def description(self) -> str:
|
|
145
|
+
return "Evaluates mathematical expressions"
|
|
146
|
+
|
|
147
|
+
async def execute(self, params: dict) -> ToolResult:
|
|
148
|
+
expr = params["expression"]
|
|
149
|
+
result = eval(expr) # In production, use a safe evaluator
|
|
150
|
+
return ToolResult(success=True, data=result)
|
|
151
|
+
|
|
152
|
+
# ReAct agent with tools
|
|
153
|
+
agent = ReActAgent(
|
|
154
|
+
llm=my_llm,
|
|
155
|
+
tools=[CalculatorTool(), WebSearchTool()],
|
|
156
|
+
max_iterations=5
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
result = await agent.process(Message(content="What is 15% of 200?"))
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Reasoning Techniques
|
|
163
|
+
|
|
164
|
+
#### Chain-of-Thought (CoT)
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from agenkit.techniques.reasoning import ChainOfThought
|
|
168
|
+
|
|
169
|
+
# Step-by-step reasoning
|
|
170
|
+
cot = ChainOfThought(
|
|
171
|
+
llm=my_llm,
|
|
172
|
+
prompt_template="Let's solve this step by step:\n{query}",
|
|
173
|
+
max_steps=5
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
result = await cot.process(Message(content="What is 15 * 24?"))
|
|
177
|
+
print(result.metadata["reasoning_steps"])
|
|
178
|
+
# ["1. Multiply 15 by 20: 300", "2. Multiply 15 by 4: 60", "3. Add: 360"]
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Tree-of-Thought (ToT)
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from agenkit.techniques.reasoning import TreeOfThought, SearchStrategy
|
|
185
|
+
|
|
186
|
+
# Multi-path exploration with backtracking
|
|
187
|
+
tot = TreeOfThought(
|
|
188
|
+
agent=my_agent,
|
|
189
|
+
branching_factor=3,
|
|
190
|
+
max_depth=4,
|
|
191
|
+
strategy=SearchStrategy.BEST_FIRST,
|
|
192
|
+
evaluator=lambda text: quality_score(text)
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
result = await tot.process(message)
|
|
196
|
+
print(result.metadata["reasoning_path"]) # Best path through tree
|
|
197
|
+
print(result.metadata["best_score"]) # 0.95
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### Self-Consistency
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from agenkit.techniques.reasoning import SelfConsistency
|
|
204
|
+
|
|
205
|
+
# Generate multiple reasoning paths and vote
|
|
206
|
+
sc = SelfConsistency(
|
|
207
|
+
agent=my_cot_agent,
|
|
208
|
+
num_samples=7,
|
|
209
|
+
voting_strategy="majority"
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
result = await sc.process(message)
|
|
213
|
+
print(result.metadata["consistency_score"]) # 0.85
|
|
214
|
+
print(result.metadata["answer_counts"]) # {"42": 5, "40": 2}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Observability
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from agenkit.observability import TracingMiddleware
|
|
221
|
+
from opentelemetry import trace
|
|
222
|
+
|
|
223
|
+
# Enable distributed tracing
|
|
224
|
+
tracer = trace.get_tracer(__name__)
|
|
225
|
+
agent = TracingMiddleware(agent, tracer=tracer)
|
|
226
|
+
|
|
227
|
+
# Now all agent calls are traced
|
|
228
|
+
with tracer.start_as_current_span("process_request"):
|
|
229
|
+
result = await agent.process(message)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Evaluation
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from agenkit.evaluation import BenchmarkRunner, Recorder
|
|
236
|
+
|
|
237
|
+
# Record agent sessions for regression testing
|
|
238
|
+
recorder = Recorder("./sessions")
|
|
239
|
+
agent = recorder.wrap(agent)
|
|
240
|
+
|
|
241
|
+
# Run benchmarks
|
|
242
|
+
runner = BenchmarkRunner()
|
|
243
|
+
results = await runner.run_benchmark(
|
|
244
|
+
agent=agent,
|
|
245
|
+
test_cases=my_test_cases
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
print(f"Success rate: {results.success_rate}")
|
|
249
|
+
print(f"Avg latency: {results.avg_latency_ms}ms")
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Package Structure
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
agenkit/
|
|
256
|
+
├── __init__.py # Core exports
|
|
257
|
+
├── interfaces.py # Agent, Message, Tool interfaces
|
|
258
|
+
├── introspection.py # Agent introspection utilities
|
|
259
|
+
├── composition/ # Sequential, Parallel, Conditional
|
|
260
|
+
├── patterns/ # 32 agent patterns
|
|
261
|
+
│ ├── sequential.py # Pipeline execution
|
|
262
|
+
│ ├── parallel.py # Concurrent execution
|
|
263
|
+
│ ├── router.py # Conditional routing
|
|
264
|
+
│ ├── conversational.py # History management
|
|
265
|
+
│ ├── react.py # Reasoning + Acting
|
|
266
|
+
│ ├── reflection.py # Self-critique loop
|
|
267
|
+
│ ├── planning.py # Task decomposition
|
|
268
|
+
│ ├── autonomous.py # Goal-driven agents
|
|
269
|
+
│ ├── memory.py # Memory hierarchy
|
|
270
|
+
│ └── ... [23 more patterns]
|
|
271
|
+
├── techniques/ # Reasoning techniques
|
|
272
|
+
│ └── reasoning/
|
|
273
|
+
│ ├── chain_of_thought.py # CoT prompting
|
|
274
|
+
│ ├── tree_of_thought.py # ToT search
|
|
275
|
+
│ ├── self_consistency.py # Voting strategy
|
|
276
|
+
│ ├── graph_of_thought.py # Graph reasoning
|
|
277
|
+
│ └── ... [more techniques]
|
|
278
|
+
├── middleware/ # Production middleware
|
|
279
|
+
│ ├── retry.py # Automatic retries
|
|
280
|
+
│ ├── circuit_breaker.py # Circuit breaker pattern
|
|
281
|
+
│ ├── timeout.py # Timeout handling
|
|
282
|
+
│ ├── rate_limiter.py # Rate limiting
|
|
283
|
+
│ ├── caching.py # Response caching
|
|
284
|
+
│ └── batching.py # Request batching
|
|
285
|
+
├── adapters/ # LLM adapters
|
|
286
|
+
│ ├── anthropic.py # Claude API
|
|
287
|
+
│ ├── openai.py # OpenAI API
|
|
288
|
+
│ ├── bedrock.py # AWS Bedrock
|
|
289
|
+
│ └── gemini.py # Google Gemini
|
|
290
|
+
├── transport/ # Communication protocols
|
|
291
|
+
│ ├── http.py # HTTP/REST
|
|
292
|
+
│ ├── grpc.py # gRPC
|
|
293
|
+
│ └── websocket.py # WebSocket
|
|
294
|
+
├── observability/ # Tracing and metrics
|
|
295
|
+
│ ├── tracing.py # OpenTelemetry integration
|
|
296
|
+
│ └── metrics.py # Metrics collection
|
|
297
|
+
├── evaluation/ # Testing and optimization
|
|
298
|
+
│ ├── recorder.py # Session recording
|
|
299
|
+
│ ├── benchmarks.py # Performance benchmarks
|
|
300
|
+
│ └── optimizer.py # Hyperparameter optimization
|
|
301
|
+
└── budget/ # Token and cost management
|
|
302
|
+
└── limiter.py # Budget limiting
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## API Reference
|
|
306
|
+
|
|
307
|
+
See [docs/API.md](../../docs/API.md) for complete API documentation.
|
|
308
|
+
|
|
309
|
+
## Examples
|
|
310
|
+
|
|
311
|
+
Comprehensive examples are available in [examples/](../../examples/):
|
|
312
|
+
|
|
313
|
+
- **Basics**: Simple agents, composition patterns
|
|
314
|
+
- **Patterns**: All 32 agent patterns with real-world use cases
|
|
315
|
+
- **Techniques**: CoT, ToT, Self-Consistency, and more
|
|
316
|
+
- **Integrations**: LLM adapters, observability, deployment
|
|
317
|
+
- **Production**: Resilience, scaling, monitoring
|
|
318
|
+
|
|
319
|
+
## Testing
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
# Run all tests
|
|
323
|
+
pytest
|
|
324
|
+
|
|
325
|
+
# Run specific test suite
|
|
326
|
+
pytest tests/test_patterns.py
|
|
327
|
+
|
|
328
|
+
# Run with coverage
|
|
329
|
+
pytest --cov=agenkit
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Development
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
# Install in development mode
|
|
336
|
+
pip install -e ".[dev]"
|
|
337
|
+
|
|
338
|
+
# Run linting
|
|
339
|
+
ruff check agenkit/
|
|
340
|
+
black agenkit/
|
|
341
|
+
|
|
342
|
+
# Run type checking
|
|
343
|
+
mypy agenkit/
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Migration from Other Frameworks
|
|
347
|
+
|
|
348
|
+
See [docs/MIGRATION.md](../../docs/MIGRATION.md) for migration guides from:
|
|
349
|
+
- LangChain
|
|
350
|
+
- LlamaIndex
|
|
351
|
+
- Haystack
|
|
352
|
+
- Semantic Kernel
|
|
353
|
+
|
|
354
|
+
## Performance
|
|
355
|
+
|
|
356
|
+
Python is the reference implementation optimized for developer experience. For production workloads requiring maximum performance:
|
|
357
|
+
|
|
358
|
+
- **Go**: 18x faster, see [../agenkit-go/](../agenkit-go/)
|
|
359
|
+
- **Rust**: 22x faster, see [../agenkit-rust/](../agenkit-rust/)
|
|
360
|
+
- **C++**: 25x faster, see [../agenkit-cpp/](../agenkit-cpp/)
|
|
361
|
+
|
|
362
|
+
All implementations maintain 100% behavioral parity - write in Python, deploy in any language.
|
|
363
|
+
|
|
364
|
+
## Cross-Language Compatibility
|
|
365
|
+
|
|
366
|
+
Agenkit agents can communicate across languages using HTTP or gRPC:
|
|
367
|
+
|
|
368
|
+
```python
|
|
369
|
+
# Python agent calling Go agent
|
|
370
|
+
from agenkit.transport import HTTPClient
|
|
371
|
+
|
|
372
|
+
go_agent = HTTPClient("http://localhost:8080")
|
|
373
|
+
result = await go_agent.process(message)
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
See [docs/PATTERNS.md](../../docs/PATTERNS.md#cross-language) for details.
|
|
377
|
+
|
|
378
|
+
## Contributing
|
|
379
|
+
|
|
380
|
+
Contributions are welcome! See [CONTRIBUTING.md](../../CONTRIBUTING.md) for guidelines.
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
Apache 2.0 - See [LICENSE](../../LICENSE) for details.
|
|
385
|
+
|
|
386
|
+
## Links
|
|
387
|
+
|
|
388
|
+
- **Documentation**: https://agenkit.dev
|
|
389
|
+
- **GitHub**: https://github.com/scttfrdmn/agenkit
|
|
390
|
+
- **PyPI**: https://pypi.org/project/agenkit/
|
|
391
|
+
- **Discord**: https://discord.gg/agenkit
|
|
392
|
+
- **Twitter**: @agenkit
|
|
393
|
+
|
|
394
|
+
## Support
|
|
395
|
+
|
|
396
|
+
- **Issues**: https://github.com/scttfrdmn/agenkit/issues
|
|
397
|
+
- **Discussions**: https://github.com/scttfrdmn/agenkit/discussions
|
|
398
|
+
- **Email**: support@agenkit.dev
|
agenkit/__init__.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""
|
|
2
|
+
agenkit: The foundation layer for AI agents.
|
|
3
|
+
|
|
4
|
+
Minimal, perfect primitives for agent communication.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from importlib.metadata import PackageNotFoundError
|
|
8
|
+
from importlib.metadata import version as _package_version
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from agenkit.composition import ConditionalAgent, FallbackAgent, ParallelAgent, SequentialAgent
|
|
12
|
+
from agenkit.interfaces import (
|
|
13
|
+
Agent,
|
|
14
|
+
CallOptions,
|
|
15
|
+
IntrospectionResult,
|
|
16
|
+
Message,
|
|
17
|
+
Tool,
|
|
18
|
+
ToolResult,
|
|
19
|
+
)
|
|
20
|
+
from agenkit.patterns import Task
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
# Read from installed distribution metadata rather than hardcoding, so this
|
|
24
|
+
# cannot drift from pyproject.toml the way it did for 77 minor versions
|
|
25
|
+
# (#842: this said 0.10.0 while the same package's pyproject said 0.70.0).
|
|
26
|
+
__version__ = _package_version("agenkit")
|
|
27
|
+
except PackageNotFoundError: # pragma: no cover - running from a source tree
|
|
28
|
+
# Not installed (e.g. imported straight from a checkout). Fall back to the
|
|
29
|
+
# VERSION file, which is the source of truth that pyproject.toml derives from.
|
|
30
|
+
_version_file = Path(__file__).resolve().parent.parent / "VERSION"
|
|
31
|
+
__version__ = (
|
|
32
|
+
_version_file.read_text(encoding="utf-8").strip() if _version_file.is_file() else "unknown"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
# Core interfaces
|
|
37
|
+
"Agent",
|
|
38
|
+
# Per-call inference options
|
|
39
|
+
"CallOptions",
|
|
40
|
+
# Composition patterns
|
|
41
|
+
"ConditionalAgent",
|
|
42
|
+
"FallbackAgent",
|
|
43
|
+
# Introspection
|
|
44
|
+
"IntrospectionResult",
|
|
45
|
+
"Message",
|
|
46
|
+
"ParallelAgent",
|
|
47
|
+
"SequentialAgent",
|
|
48
|
+
# Agent patterns
|
|
49
|
+
"Task",
|
|
50
|
+
"Tool",
|
|
51
|
+
"ToolResult",
|
|
52
|
+
]
|