dacp 0.3.0__py3-none-any.whl → 0.3.2__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.
- dacp/__init__.py +23 -4
- dacp/intelligence.py +241 -210
- dacp/llm.py +13 -6
- dacp/logging_config.py +129 -0
- dacp/main.py +7 -13
- dacp/orchestrator.py +225 -201
- dacp/tools.py +72 -22
- dacp-0.3.2.dist-info/METADATA +805 -0
- dacp-0.3.2.dist-info/RECORD +15 -0
- dacp-0.3.0.dist-info/METADATA +0 -369
- dacp-0.3.0.dist-info/RECORD +0 -14
- {dacp-0.3.0.dist-info → dacp-0.3.2.dist-info}/WHEEL +0 -0
- {dacp-0.3.0.dist-info → dacp-0.3.2.dist-info}/licenses/LICENSE +0 -0
- {dacp-0.3.0.dist-info → dacp-0.3.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
dacp/__init__.py,sha256=5EUO_gnPX7DISwAuPPkDSWrHoH9MNEoDRjDG16c7q_w,1351
|
2
|
+
dacp/exceptions.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
dacp/intelligence.py,sha256=z8RqRYXKKKDd9MCm1KLBNQ3DJ9Zl4ZntbjFcaqtuv9s,9713
|
4
|
+
dacp/llm.py,sha256=K78QefD3LCOBTrsNHtfRs-UzcHNYCJNxcJ28HGirwfU,1064
|
5
|
+
dacp/logging_config.py,sha256=g5iMe9mloZag4oFQ9FQrRTikDTCI-XxeTGX0Y1KXVMw,3927
|
6
|
+
dacp/main.py,sha256=YReioZotkURiYMuMLVf_-hPzVPSpqA5Esgwz7D36DhE,229
|
7
|
+
dacp/orchestrator.py,sha256=5GxAVQFYW6OkNB8O5TT2eaJtQat7YUN_je7j-V0kXNM,9315
|
8
|
+
dacp/protocol.py,sha256=DVhLTdyDVlAu8ETSEX8trPeycKfMeirHwcWQ8-BY7eA,1026
|
9
|
+
dacp/tools.py,sha256=wfuUQ12UVvyMLUcDA4GGxwwzQJ-k4ftWbewg7qwNQGg,2872
|
10
|
+
dacp/types.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
+
dacp-0.3.2.dist-info/licenses/LICENSE,sha256=tb5kgUYRypHqAy8wlrJUBSYI5l1SBmawSYHmCC-MVW0,1074
|
12
|
+
dacp-0.3.2.dist-info/METADATA,sha256=RHlO4D7HV5kNPendOYH9yd3c5hzDOsIKf8bMSJcaNEk,25756
|
13
|
+
dacp-0.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
14
|
+
dacp-0.3.2.dist-info/top_level.txt,sha256=Qxy0cy5jl7ttTQoGFlY9LXB6CbSvsekJ2y0P8I7L1zA,5
|
15
|
+
dacp-0.3.2.dist-info/RECORD,,
|
dacp-0.3.0.dist-info/METADATA
DELETED
@@ -1,369 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: dacp
|
3
|
-
Version: 0.3.0
|
4
|
-
Summary: Declarative Agent Communication Protocol - A protocol for managing LLM/agent communications and tool function calls
|
5
|
-
Author-email: Andrew Whitehouse <andrew.whitehouse@example.com>
|
6
|
-
License: MIT
|
7
|
-
Project-URL: Homepage, https://github.com/andrewwhitehouse/dacp
|
8
|
-
Project-URL: Repository, https://github.com/andrewwhitehouse/dacp
|
9
|
-
Project-URL: Documentation, https://github.com/andrewwhitehouse/dacp#readme
|
10
|
-
Project-URL: Issues, https://github.com/andrewwhitehouse/dacp/issues
|
11
|
-
Keywords: llm,agent,communication,protocol,ai,ml
|
12
|
-
Classifier: Development Status :: 4 - Beta
|
13
|
-
Classifier: Intended Audience :: Developers
|
14
|
-
Classifier: License :: OSI Approved :: MIT License
|
15
|
-
Classifier: Operating System :: OS Independent
|
16
|
-
Classifier: Programming Language :: Python :: 3
|
17
|
-
Classifier: Programming Language :: Python :: 3.8
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
19
|
-
Classifier: Programming Language :: Python :: 3.10
|
20
|
-
Classifier: Programming Language :: Python :: 3.11
|
21
|
-
Classifier: Programming Language :: Python :: 3.12
|
22
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
23
|
-
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
24
|
-
Requires-Python: >=3.8
|
25
|
-
Description-Content-Type: text/markdown
|
26
|
-
License-File: LICENSE
|
27
|
-
Requires-Dist: requests>=2.25.0
|
28
|
-
Requires-Dist: pyyaml>=5.4.0
|
29
|
-
Provides-Extra: openai
|
30
|
-
Requires-Dist: openai>=1.0.0; extra == "openai"
|
31
|
-
Provides-Extra: anthropic
|
32
|
-
Requires-Dist: anthropic>=0.18.0; extra == "anthropic"
|
33
|
-
Provides-Extra: local
|
34
|
-
Requires-Dist: requests>=2.25.0; extra == "local"
|
35
|
-
Provides-Extra: all
|
36
|
-
Requires-Dist: openai>=1.0.0; extra == "all"
|
37
|
-
Requires-Dist: anthropic>=0.18.0; extra == "all"
|
38
|
-
Provides-Extra: dev
|
39
|
-
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
40
|
-
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
41
|
-
Requires-Dist: black>=22.0.0; extra == "dev"
|
42
|
-
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
43
|
-
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
44
|
-
Requires-Dist: types-requests>=2.25.0; extra == "dev"
|
45
|
-
Requires-Dist: types-PyYAML>=6.0.0; extra == "dev"
|
46
|
-
Dynamic: license-file
|
47
|
-
|
48
|
-
# DACP - Declarative Agent Communication Protocol
|
49
|
-
|
50
|
-
A Python library for managing LLM/agent communications and tool function calls following the OAS Open Agent Specification.
|
51
|
-
|
52
|
-
## Installation
|
53
|
-
|
54
|
-
```bash
|
55
|
-
pip install -e .
|
56
|
-
```
|
57
|
-
|
58
|
-
## Quick Start
|
59
|
-
|
60
|
-
```python
|
61
|
-
import dacp
|
62
|
-
|
63
|
-
# Create an orchestrator to manage agents
|
64
|
-
orchestrator = dacp.Orchestrator()
|
65
|
-
|
66
|
-
# Create and register an agent
|
67
|
-
class MyAgent:
|
68
|
-
def handle_message(self, message):
|
69
|
-
return {"response": f"Hello {message.get('name', 'World')}!"}
|
70
|
-
|
71
|
-
agent = MyAgent()
|
72
|
-
orchestrator.register_agent("my-agent", agent)
|
73
|
-
|
74
|
-
# Send a message to the agent
|
75
|
-
response = orchestrator.send_message("my-agent", {"name": "Alice"})
|
76
|
-
print(response) # {"response": "Hello Alice!"}
|
77
|
-
|
78
|
-
# Use built-in tools
|
79
|
-
result = dacp.file_writer("./output/greeting.txt", "Hello, World!")
|
80
|
-
print(result["message"]) # "Successfully wrote 13 characters to ./output/greeting.txt"
|
81
|
-
|
82
|
-
# Use intelligence providers (supports multiple LLM providers)
|
83
|
-
intelligence_config = {
|
84
|
-
"engine": "anthropic",
|
85
|
-
"model": "claude-3-haiku-20240307",
|
86
|
-
"api_key": "your-api-key" # or set ANTHROPIC_API_KEY env var
|
87
|
-
}
|
88
|
-
response = dacp.invoke_intelligence("What is the weather like today?", intelligence_config)
|
89
|
-
|
90
|
-
# Or use the legacy call_llm function for OpenAI
|
91
|
-
response = dacp.call_llm("What is the weather like today?")
|
92
|
-
```
|
93
|
-
|
94
|
-
## Features
|
95
|
-
|
96
|
-
- **Agent Orchestration**: Central management of multiple agents with message routing
|
97
|
-
- **Tool Registry**: Register and manage custom tools for LLM agents
|
98
|
-
- **Built-in Tools**: Includes a `file_writer` tool that automatically creates parent directories
|
99
|
-
- **LLM Integration**: Built-in support for OpenAI models (extensible)
|
100
|
-
- **Protocol Parsing**: Parse and validate agent responses
|
101
|
-
- **Tool Execution**: Safe execution of registered tools
|
102
|
-
- **Conversation History**: Track and query agent interactions
|
103
|
-
- **OAS Compliance**: Follows Open Agent Specification standards
|
104
|
-
|
105
|
-
## API Reference
|
106
|
-
|
107
|
-
### Orchestrator
|
108
|
-
|
109
|
-
- `Orchestrator()`: Create a new orchestrator instance
|
110
|
-
- `register_agent(agent_id: str, agent) -> None`: Register an agent
|
111
|
-
- `unregister_agent(agent_id: str) -> bool`: Remove an agent
|
112
|
-
- `send_message(agent_id: str, message: Dict) -> Dict`: Send message to specific agent
|
113
|
-
- `broadcast_message(message: Dict, exclude_agents: List[str] = None) -> Dict`: Send message to all agents
|
114
|
-
- `get_conversation_history(agent_id: str = None) -> List[Dict]`: Get conversation history
|
115
|
-
- `clear_history() -> None`: Clear conversation history
|
116
|
-
- `get_session_info() -> Dict`: Get current session information
|
117
|
-
|
118
|
-
### Tools
|
119
|
-
|
120
|
-
- `register_tool(tool_id: str, func)`: Register a new tool
|
121
|
-
- `run_tool(tool_id: str, args: Dict) -> dict`: Execute a registered tool
|
122
|
-
- `TOOL_REGISTRY`: Access the current tool registry
|
123
|
-
- `file_writer(path: str, content: str) -> dict`: Write content to file, creating directories automatically
|
124
|
-
|
125
|
-
### Intelligence (Multi-Provider LLM Support)
|
126
|
-
|
127
|
-
- `invoke_intelligence(prompt: str, config: dict) -> str`: Call any supported LLM provider
|
128
|
-
- `validate_config(config: dict) -> bool`: Validate intelligence configuration
|
129
|
-
- `get_supported_engines() -> list`: Get list of supported engines
|
130
|
-
|
131
|
-
### LLM (Legacy)
|
132
|
-
|
133
|
-
- `call_llm(prompt: str, model: str = "gpt-4") -> str`: Call OpenAI (legacy function)
|
134
|
-
|
135
|
-
### Protocol
|
136
|
-
|
137
|
-
- `parse_agent_response(response: str | dict) -> dict`: Parse agent response
|
138
|
-
- `is_tool_request(msg: dict) -> bool`: Check if message is a tool request
|
139
|
-
- `get_tool_request(msg: dict) -> tuple[str, dict]`: Extract tool request details
|
140
|
-
- `wrap_tool_result(name: str, result: dict) -> dict`: Wrap tool result for agent
|
141
|
-
- `is_final_response(msg: dict) -> bool`: Check if message is a final response
|
142
|
-
- `get_final_response(msg: dict) -> dict`: Extract final response
|
143
|
-
|
144
|
-
## Agent Development
|
145
|
-
|
146
|
-
### Creating an Agent
|
147
|
-
|
148
|
-
Agents must implement a `handle_message` method:
|
149
|
-
|
150
|
-
```python
|
151
|
-
import dacp
|
152
|
-
|
153
|
-
class GreetingAgent:
|
154
|
-
def handle_message(self, message):
|
155
|
-
name = message.get("name", "World")
|
156
|
-
task = message.get("task")
|
157
|
-
|
158
|
-
if task == "greet":
|
159
|
-
return {"response": f"Hello, {name}!"}
|
160
|
-
elif task == "farewell":
|
161
|
-
return {"response": f"Goodbye, {name}!"}
|
162
|
-
else:
|
163
|
-
return {"error": f"Unknown task: {task}"}
|
164
|
-
|
165
|
-
# Register the agent
|
166
|
-
orchestrator = dacp.Orchestrator()
|
167
|
-
agent = GreetingAgent()
|
168
|
-
orchestrator.register_agent("greeter", agent)
|
169
|
-
|
170
|
-
# Use the agent
|
171
|
-
response = orchestrator.send_message("greeter", {
|
172
|
-
"task": "greet",
|
173
|
-
"name": "Alice"
|
174
|
-
})
|
175
|
-
print(response) # {"response": "Hello, Alice!"}
|
176
|
-
```
|
177
|
-
|
178
|
-
### Agent Base Class
|
179
|
-
|
180
|
-
You can also inherit from the `Agent` base class:
|
181
|
-
|
182
|
-
```python
|
183
|
-
import dacp
|
184
|
-
|
185
|
-
class MyAgent(dacp.Agent):
|
186
|
-
def handle_message(self, message):
|
187
|
-
return {"processed": message}
|
188
|
-
```
|
189
|
-
|
190
|
-
### Tool Requests from Agents
|
191
|
-
|
192
|
-
Agents can request tool execution by returning properly formatted responses:
|
193
|
-
|
194
|
-
```python
|
195
|
-
class ToolUsingAgent:
|
196
|
-
def handle_message(self, message):
|
197
|
-
if message.get("task") == "write_file":
|
198
|
-
return {
|
199
|
-
"tool_request": {
|
200
|
-
"name": "file_writer",
|
201
|
-
"args": {
|
202
|
-
"path": "./output/agent_file.txt",
|
203
|
-
"content": "Hello from agent!"
|
204
|
-
}
|
205
|
-
}
|
206
|
-
}
|
207
|
-
return {"response": "Task completed"}
|
208
|
-
|
209
|
-
# The orchestrator will automatically execute the tool and return results
|
210
|
-
orchestrator = dacp.Orchestrator()
|
211
|
-
agent = ToolUsingAgent()
|
212
|
-
orchestrator.register_agent("file-agent", agent)
|
213
|
-
|
214
|
-
response = orchestrator.send_message("file-agent", {"task": "write_file"})
|
215
|
-
# Tool will be executed automatically
|
216
|
-
```
|
217
|
-
|
218
|
-
## Intelligence Configuration
|
219
|
-
|
220
|
-
DACP supports multiple LLM providers through the `invoke_intelligence` function. Configure different providers using a configuration dictionary:
|
221
|
-
|
222
|
-
### OpenAI
|
223
|
-
|
224
|
-
```python
|
225
|
-
import dacp
|
226
|
-
|
227
|
-
openai_config = {
|
228
|
-
"engine": "openai",
|
229
|
-
"model": "gpt-4", # or "gpt-3.5-turbo", "gpt-4-turbo", etc.
|
230
|
-
"api_key": "your-openai-key", # or set OPENAI_API_KEY env var
|
231
|
-
"endpoint": "https://api.openai.com/v1", # optional, uses default
|
232
|
-
"temperature": 0.7, # optional, default 0.7
|
233
|
-
"max_tokens": 150 # optional, default 150
|
234
|
-
}
|
235
|
-
|
236
|
-
response = dacp.invoke_intelligence("Explain quantum computing", openai_config)
|
237
|
-
```
|
238
|
-
|
239
|
-
### Anthropic (Claude)
|
240
|
-
|
241
|
-
```python
|
242
|
-
anthropic_config = {
|
243
|
-
"engine": "anthropic",
|
244
|
-
"model": "claude-3-haiku-20240307", # or other Claude models
|
245
|
-
"api_key": "your-anthropic-key", # or set ANTHROPIC_API_KEY env var
|
246
|
-
"endpoint": "https://api.anthropic.com", # optional, uses default
|
247
|
-
"temperature": 0.7,
|
248
|
-
"max_tokens": 150
|
249
|
-
}
|
250
|
-
|
251
|
-
response = dacp.invoke_intelligence("Write a poem about AI", anthropic_config)
|
252
|
-
```
|
253
|
-
|
254
|
-
### Azure OpenAI
|
255
|
-
|
256
|
-
```python
|
257
|
-
azure_config = {
|
258
|
-
"engine": "azure",
|
259
|
-
"model": "gpt-4", # Your deployed model name
|
260
|
-
"api_key": "your-azure-key", # or set AZURE_OPENAI_API_KEY env var
|
261
|
-
"endpoint": "https://your-resource.openai.azure.com", # or set AZURE_OPENAI_ENDPOINT env var
|
262
|
-
"api_version": "2024-02-01" # optional, default provided
|
263
|
-
}
|
264
|
-
|
265
|
-
response = dacp.invoke_intelligence("Analyze this data", azure_config)
|
266
|
-
```
|
267
|
-
|
268
|
-
### Local LLMs (Ollama, etc.)
|
269
|
-
|
270
|
-
```python
|
271
|
-
# For Ollama (default local setup)
|
272
|
-
local_config = {
|
273
|
-
"engine": "local",
|
274
|
-
"model": "llama2", # or any model available in Ollama
|
275
|
-
"endpoint": "http://localhost:11434/api/generate", # Ollama default
|
276
|
-
"temperature": 0.7,
|
277
|
-
"max_tokens": 150
|
278
|
-
}
|
279
|
-
|
280
|
-
# For custom local APIs
|
281
|
-
custom_local_config = {
|
282
|
-
"engine": "local",
|
283
|
-
"model": "custom-model",
|
284
|
-
"endpoint": "http://localhost:8080/generate", # Your API endpoint
|
285
|
-
"temperature": 0.7,
|
286
|
-
"max_tokens": 150
|
287
|
-
}
|
288
|
-
|
289
|
-
response = dacp.invoke_intelligence("Tell me a story", local_config)
|
290
|
-
```
|
291
|
-
|
292
|
-
### Configuration from OAS YAML
|
293
|
-
|
294
|
-
You can load configuration from OAS (Open Agent Specification) YAML files:
|
295
|
-
|
296
|
-
```python
|
297
|
-
import yaml
|
298
|
-
import dacp
|
299
|
-
|
300
|
-
# Load config from YAML file
|
301
|
-
with open('agent_config.yaml', 'r') as f:
|
302
|
-
config = yaml.safe_load(f)
|
303
|
-
|
304
|
-
intelligence_config = config.get('intelligence', {})
|
305
|
-
response = dacp.invoke_intelligence("Hello, AI!", intelligence_config)
|
306
|
-
```
|
307
|
-
|
308
|
-
### Installation for Different Providers
|
309
|
-
|
310
|
-
Install optional dependencies for the providers you need:
|
311
|
-
|
312
|
-
```bash
|
313
|
-
# For OpenAI
|
314
|
-
pip install dacp[openai]
|
315
|
-
|
316
|
-
# For Anthropic
|
317
|
-
pip install dacp[anthropic]
|
318
|
-
|
319
|
-
# For all providers
|
320
|
-
pip install dacp[all]
|
321
|
-
|
322
|
-
# For local providers (requests is already included in base install)
|
323
|
-
pip install dacp[local]
|
324
|
-
```
|
325
|
-
|
326
|
-
## Built-in Tools
|
327
|
-
|
328
|
-
### file_writer
|
329
|
-
|
330
|
-
The `file_writer` tool automatically creates parent directories and writes content to files:
|
331
|
-
|
332
|
-
```python
|
333
|
-
import dacp
|
334
|
-
|
335
|
-
# This will create the ./output/ directory if it doesn't exist
|
336
|
-
result = dacp.file_writer("./output/file.txt", "Hello, World!")
|
337
|
-
|
338
|
-
if result["success"]:
|
339
|
-
print(f"File written: {result['path']}")
|
340
|
-
print(f"Message: {result['message']}")
|
341
|
-
else:
|
342
|
-
print(f"Error: {result['error']}")
|
343
|
-
```
|
344
|
-
|
345
|
-
**Features:**
|
346
|
-
- ✅ Automatically creates parent directories
|
347
|
-
- ✅ Handles Unicode content properly
|
348
|
-
- ✅ Returns detailed success/error information
|
349
|
-
- ✅ Safe error handling
|
350
|
-
|
351
|
-
## Development
|
352
|
-
|
353
|
-
```bash
|
354
|
-
# Install development dependencies
|
355
|
-
pip install -e .[dev]
|
356
|
-
|
357
|
-
# Run tests
|
358
|
-
pytest
|
359
|
-
|
360
|
-
# Format code
|
361
|
-
black .
|
362
|
-
|
363
|
-
# Lint code
|
364
|
-
flake8
|
365
|
-
```
|
366
|
-
|
367
|
-
## License
|
368
|
-
|
369
|
-
MIT License
|
dacp-0.3.0.dist-info/RECORD
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
dacp/__init__.py,sha256=-EFiHyOWg8IcG2FI-Hmd9wrHicGi8qAMv0cPwz0oCiU,833
|
2
|
-
dacp/exceptions.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
dacp/intelligence.py,sha256=SGLaq6dlJmeDqP0ZgT6bR_4WahNf-K7qWBaTG3yqBMI,9487
|
4
|
-
dacp/llm.py,sha256=JxHqM-aIm9pAMcVHQevbJGxrlBH4uV1ngRQdvyp9L3A,827
|
5
|
-
dacp/main.py,sha256=ZcJLymC9S5A4iO4yV7X178RLlhDrDuAwirdevUD5Yn0,470
|
6
|
-
dacp/orchestrator.py,sha256=PIur8Kts-vtUchmo7E8B59ZLm6s7C7yQ0ScK9E5FXhE,8756
|
7
|
-
dacp/protocol.py,sha256=DVhLTdyDVlAu8ETSEX8trPeycKfMeirHwcWQ8-BY7eA,1026
|
8
|
-
dacp/tools.py,sha256=FLgZa5Brni9H3Hyn336k3DGoVxIa_1rFM4WpIRXzVbc,1569
|
9
|
-
dacp/types.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
dacp-0.3.0.dist-info/licenses/LICENSE,sha256=tb5kgUYRypHqAy8wlrJUBSYI5l1SBmawSYHmCC-MVW0,1074
|
11
|
-
dacp-0.3.0.dist-info/METADATA,sha256=J9bKw2rxID--1fqZ9Z33lSs2SKTmat72zVLj-DUirU0,11220
|
12
|
-
dacp-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
13
|
-
dacp-0.3.0.dist-info/top_level.txt,sha256=Qxy0cy5jl7ttTQoGFlY9LXB6CbSvsekJ2y0P8I7L1zA,5
|
14
|
-
dacp-0.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|