argentic 0.6.0__tar.gz
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.
- argentic-0.6.0/.gitignore +42 -0
- argentic-0.6.0/LICENSE +21 -0
- argentic-0.6.0/PKG-INFO +356 -0
- argentic-0.6.0/README.md +307 -0
- argentic-0.6.0/pyproject.toml +111 -0
- argentic-0.6.0/src/__init__.py +20 -0
- argentic-0.6.0/src/__main__.py +157 -0
- argentic-0.6.0/src/cli_client.py +551 -0
- argentic-0.6.0/src/core/__init__.py +17 -0
- argentic-0.6.0/src/core/agent/agent.py +694 -0
- argentic-0.6.0/src/core/client.py +118 -0
- argentic-0.6.0/src/core/decorators.py +83 -0
- argentic-0.6.0/src/core/llm/__init__.py +0 -0
- argentic-0.6.0/src/core/llm/llm_factory.py +59 -0
- argentic-0.6.0/src/core/llm/providers/__init__.py +0 -0
- argentic-0.6.0/src/core/llm/providers/base.py +50 -0
- argentic-0.6.0/src/core/llm/providers/google_gemini.py +167 -0
- argentic-0.6.0/src/core/llm/providers/llama_cpp_cli.py +128 -0
- argentic-0.6.0/src/core/llm/providers/llama_cpp_langchain.py +145 -0
- argentic-0.6.0/src/core/llm/providers/llama_cpp_server.py +242 -0
- argentic-0.6.0/src/core/llm/providers/ollama.py +161 -0
- argentic-0.6.0/src/core/logger.py +214 -0
- argentic-0.6.0/src/core/messager/__init__.py +1 -0
- argentic-0.6.0/src/core/messager/drivers/KafkaDriver.py +285 -0
- argentic-0.6.0/src/core/messager/drivers/MQTTDriver.py +88 -0
- argentic-0.6.0/src/core/messager/drivers/RabbitMQDriver.py +261 -0
- argentic-0.6.0/src/core/messager/drivers/RedisDriver.py +78 -0
- argentic-0.6.0/src/core/messager/drivers/__init__.py +85 -0
- argentic-0.6.0/src/core/messager/messager.py +247 -0
- argentic-0.6.0/src/core/messager/protocols.py +8 -0
- argentic-0.6.0/src/core/protocol/__init__.py +0 -0
- argentic-0.6.0/src/core/protocol/enums.py +28 -0
- argentic-0.6.0/src/core/protocol/message.py +99 -0
- argentic-0.6.0/src/core/protocol/task.py +36 -0
- argentic-0.6.0/src/core/protocol/tool.py +46 -0
- argentic-0.6.0/src/core/tools/tool_base.py +265 -0
- argentic-0.6.0/src/core/tools/tool_manager.py +360 -0
- argentic-0.6.0/src/main.py +261 -0
- argentic-0.6.0/src/services/__init__.py +9 -0
- argentic-0.6.0/src/services/environment_tool_service.py +171 -0
- argentic-0.6.0/src/services/rag_tool_service.py +191 -0
- argentic-0.6.0/src/tools/Environment/README.md +204 -0
- argentic-0.6.0/src/tools/Environment/__init__.py +19 -0
- argentic-0.6.0/src/tools/Environment/environment.py +529 -0
- argentic-0.6.0/src/tools/Environment/environment_config.yaml +47 -0
- argentic-0.6.0/src/tools/Environment/environment_tool.py +420 -0
- argentic-0.6.0/src/tools/RAG/README.md +347 -0
- argentic-0.6.0/src/tools/RAG/__init__.py +0 -0
- argentic-0.6.0/src/tools/RAG/knowledge_base_tool.py +220 -0
- argentic-0.6.0/src/tools/RAG/rag.py +194 -0
- argentic-0.6.0/src/tools/RAG/rag_config.yaml +43 -0
- argentic-0.6.0/src/tools/__init__.py +10 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.env
|
|
2
|
+
.venv/
|
|
3
|
+
env/
|
|
4
|
+
venv/
|
|
5
|
+
ENV/
|
|
6
|
+
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.pyc
|
|
9
|
+
*.pyo
|
|
10
|
+
*.pyd
|
|
11
|
+
*.cpython-*
|
|
12
|
+
*$py.class
|
|
13
|
+
|
|
14
|
+
build/
|
|
15
|
+
dist/
|
|
16
|
+
sdist/
|
|
17
|
+
*.egg-info/
|
|
18
|
+
*.egg
|
|
19
|
+
|
|
20
|
+
*.sqlite3
|
|
21
|
+
*.db
|
|
22
|
+
*.db-journal
|
|
23
|
+
*_db/
|
|
24
|
+
|
|
25
|
+
*.log
|
|
26
|
+
|
|
27
|
+
.coverage
|
|
28
|
+
.coverage.*
|
|
29
|
+
htmlcov/
|
|
30
|
+
.pytest_cache/
|
|
31
|
+
nosetests.xml
|
|
32
|
+
coverage.xml
|
|
33
|
+
|
|
34
|
+
.mypy_cache/
|
|
35
|
+
.pytype/
|
|
36
|
+
.dmypy.json
|
|
37
|
+
dmypy.json
|
|
38
|
+
|
|
39
|
+
.DS_Store
|
|
40
|
+
Thumbs.db
|
|
41
|
+
|
|
42
|
+
_site/
|
argentic-0.6.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yuriy Medvedev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
argentic-0.6.0/PKG-INFO
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: argentic
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Author-email: Iurii <angkira0@gmail.com>
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: ai,ai agent,chromadb,langchain,ollama,rag,sentence-transformers
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Requires-Dist: aiomqtt>=2.4.0
|
|
13
|
+
Requires-Dist: chromadb<2,>=1.0.7
|
|
14
|
+
Requires-Dist: langchain-community<0.4,>=0.3.23
|
|
15
|
+
Requires-Dist: langchain-google-genai>=2.1.4
|
|
16
|
+
Requires-Dist: langchain-huggingface<0.2,>=0.1.2
|
|
17
|
+
Requires-Dist: langchain-ollama<0.4,>=0.3.2
|
|
18
|
+
Requires-Dist: langchain<0.4,>=0.3.24
|
|
19
|
+
Requires-Dist: ollama<0.5,>=0.4.8
|
|
20
|
+
Requires-Dist: paho-mqtt<3,>=2.1.0
|
|
21
|
+
Requires-Dist: python-dotenv
|
|
22
|
+
Requires-Dist: pyyaml<7,>=6.0.2
|
|
23
|
+
Requires-Dist: requests<3,>=2.31.0
|
|
24
|
+
Requires-Dist: sentence-transformers<5,>=4.1.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: black<26,>=25.1.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: commitizen<5,>=4.7.1; extra == 'dev'
|
|
28
|
+
Requires-Dist: flake8>=7.2.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: isort<7,>=6.0.1; extra == 'dev'
|
|
30
|
+
Requires-Dist: pre-commit<5,>=4.2.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pyrefly>=0.15.2; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest-asyncio<0.24,>=0.23.5; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest<9,>=8.0.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: python-on-whales>=0.70.0; extra == 'dev'
|
|
35
|
+
Provides-Extra: docs
|
|
36
|
+
Requires-Dist: mkdocs-macros-plugin>=1.3.7; extra == 'docs'
|
|
37
|
+
Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
|
|
38
|
+
Requires-Dist: mkdocs-same-dir>=0.1.3; extra == 'docs'
|
|
39
|
+
Requires-Dist: mkdocs>=1.6.0; extra == 'docs'
|
|
40
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == 'docs'
|
|
41
|
+
Requires-Dist: pymdown-extensions>=10.0; extra == 'docs'
|
|
42
|
+
Provides-Extra: kafka
|
|
43
|
+
Requires-Dist: aiokafka>=0.12.0; extra == 'kafka'
|
|
44
|
+
Provides-Extra: rabbitmq
|
|
45
|
+
Requires-Dist: aio-pika>=9.5.5; extra == 'rabbitmq'
|
|
46
|
+
Provides-Extra: redis
|
|
47
|
+
Requires-Dist: aioredis>=2.0.1; extra == 'redis'
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
|
|
50
|
+
# Argentic
|
|
51
|
+
|
|
52
|
+
Microframework for building and running local AI agents.
|
|
53
|
+
|
|
54
|
+
{: .styled-logo }
|
|
55
|
+
|
|
56
|
+
[](https://github.com/angkira/argentic/actions/workflows/python-app.yml)
|
|
57
|
+
|
|
58
|
+
Argentic provides a lightweight, configurable framework designed to simplify the setup and operation of local AI agents. It integrates with various Large Language Model (LLM) backends and utilizes a messaging protocol (currently MQTT) for flexible communication between the core agent, tools, and clients.
|
|
59
|
+
|
|
60
|
+
## Features
|
|
61
|
+
|
|
62
|
+
- **Modular Design**: Core components include an `Agent`, a `Messager` for communication, and an `LLMProvider` for interacting with language models.
|
|
63
|
+
- **Multiple LLM Backends**: Supports various LLMs through a factory pattern, including:
|
|
64
|
+
- Ollama (via `ollama` Python library)
|
|
65
|
+
- Llama.cpp (via HTTP server or direct CLI interaction)
|
|
66
|
+
- Google Gemini (via API)
|
|
67
|
+
- **Configuration Driven**: Easily configure LLM providers, messaging brokers (MQTT), communication topics, and logging via `config.yaml`.
|
|
68
|
+
- **Command-Line Interface**: Start different components (agent, example tools, CLI client) using `start.sh`. Configure config path and log level via CLI arguments (`--config-path`, `--log-level`) or environment variables (`CONFIG_PATH`, `LOG_LEVEL`).
|
|
69
|
+
- **Messaging Protocol**: Uses MQTT for decoupled communication between the agent and potential tools or clients. Includes message classes for defined interactions (e.g., `AskQuestionMessage`).
|
|
70
|
+
- **Extensible Tool System**: Designed to integrate external tools via messaging. Includes an example RAG (Retrieval-Augmented Generation) tool (`src/services/rag_tool_service.py`) demonstrating this capability.
|
|
71
|
+
- **CLI Client**: A simple command-line client (`src/cli_client.py`) for interacting with the agent.
|
|
72
|
+
- **Graceful Shutdown**: Handles termination signals for proper cleanup.
|
|
73
|
+
|
|
74
|
+
## Getting Started
|
|
75
|
+
|
|
76
|
+
1. **Clone the repository:**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
git clone https://github.com/angkira/argentic.git
|
|
80
|
+
cd argentic
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
2. **Set up Python environment:**
|
|
84
|
+
You have two options:
|
|
85
|
+
|
|
86
|
+
**Option 1: Using the installation script**
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# This will create a virtual environment and install the package in development mode
|
|
90
|
+
./install.sh
|
|
91
|
+
source .venv/bin/activate
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Option 2: Manual setup**
|
|
95
|
+
It's recommended to use a virtual environment. The project uses `uv` (or `pip`) and `pyproject.toml`.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Using uv
|
|
99
|
+
uv venv
|
|
100
|
+
uv sync
|
|
101
|
+
source .venv/bin/activate # Or your environment's activation script
|
|
102
|
+
|
|
103
|
+
# Or using pip
|
|
104
|
+
python -m venv .venv
|
|
105
|
+
source .venv/bin/activate
|
|
106
|
+
pip install -e .
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
3. **Configure:**
|
|
110
|
+
- Copy or rename `config.yaml.example` to `config.yaml` (if an example exists) or edit `config.yaml` directly.
|
|
111
|
+
- Set up your desired LLM provider (`llm` section).
|
|
112
|
+
- Configure the MQTT broker details (`messaging` section).
|
|
113
|
+
- Set any required API keys or environment variables (e.g., `GOOGLE_GEMINI_API_KEY` if using Gemini). Refer to `.env.example` if provided.
|
|
114
|
+
4. **Run Components:**
|
|
115
|
+
Use the `start.sh` script:
|
|
116
|
+
|
|
117
|
+
- Run the main agent:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
./start.sh agent [--config-path path/to/config.yaml] [--log-level DEBUG]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- Run the example RAG tool service (optional, in a separate terminal):
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
./start.sh rag
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- Run the CLI client to interact (optional, in a separate terminal):
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
./start.sh cli
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Running as Python Module
|
|
136
|
+
|
|
137
|
+
Alternatively, you can run Argentic as a Python module using the modern `python -m` interface. This method provides the same functionality as the shell scripts but integrates better with Python packaging conventions.
|
|
138
|
+
|
|
139
|
+
### Module Command Interface
|
|
140
|
+
|
|
141
|
+
After installation (either via `./install.sh` or manual setup), you can use:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Run the main agent
|
|
145
|
+
python -m argentic agent --config-path config.yaml --log-level INFO
|
|
146
|
+
|
|
147
|
+
# Run the RAG tool service
|
|
148
|
+
python -m argentic rag --config-path config.yaml
|
|
149
|
+
|
|
150
|
+
# Run the environment tool service
|
|
151
|
+
python -m argentic environment --config-path config.yaml
|
|
152
|
+
|
|
153
|
+
# Run the CLI client
|
|
154
|
+
python -m argentic cli --config-path config.yaml
|
|
155
|
+
|
|
156
|
+
# Get help
|
|
157
|
+
python -m argentic --help
|
|
158
|
+
python -m argentic agent --help
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Console Script (After Installation)
|
|
162
|
+
|
|
163
|
+
When installed in a Python environment, you can also use the shorter console command:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# All the same commands work without 'python -m'
|
|
167
|
+
argentic agent --config-path config.yaml --log-level INFO
|
|
168
|
+
argentic rag --config-path config.yaml
|
|
169
|
+
argentic environment --config-path config.yaml
|
|
170
|
+
argentic cli --config-path config.yaml
|
|
171
|
+
argentic --help
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Configuration Options
|
|
175
|
+
|
|
176
|
+
Both interfaces support the same global options:
|
|
177
|
+
|
|
178
|
+
- `--config-path`: Path to configuration file (default: `config.yaml` or `$CONFIG_PATH`)
|
|
179
|
+
- `--log-level`: Logging level - DEBUG, INFO, WARNING, ERROR, CRITICAL (default: `INFO` or `$LOG_LEVEL`)
|
|
180
|
+
|
|
181
|
+
### Available Subcommands
|
|
182
|
+
|
|
183
|
+
- **`agent`**: Start the main AI agent service
|
|
184
|
+
- **`rag`**: Start the RAG (Retrieval-Augmented Generation) tool service
|
|
185
|
+
- **`environment`**: Start the environment tool service
|
|
186
|
+
- **`cli`**: Start the interactive command-line client
|
|
187
|
+
|
|
188
|
+
### Examples
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Start agent with custom config and debug logging
|
|
192
|
+
python -m argentic agent --config-path prod-config.yaml --log-level DEBUG
|
|
193
|
+
|
|
194
|
+
# Start RAG service with default settings
|
|
195
|
+
python -m argentic rag
|
|
196
|
+
|
|
197
|
+
# Interactive CLI session
|
|
198
|
+
python -m argentic cli
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Using as a Python Package
|
|
202
|
+
|
|
203
|
+
After installation, you can import the Argentic components in your Python code using simplified imports:
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
# Option 1: Import directly from the main package
|
|
207
|
+
from argentic import Agent, Messager, LLMFactory
|
|
208
|
+
|
|
209
|
+
# Option 2: Import from specific modules with reduced nesting
|
|
210
|
+
from argentic.core import Agent, Messager, LLMFactory
|
|
211
|
+
|
|
212
|
+
# Option 3: Import specific tools
|
|
213
|
+
from argentic.tools import BaseTool, ToolManager
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
You can also create custom tools or extend the core functionality by subclassing the base classes.
|
|
217
|
+
|
|
218
|
+
## Configuration (`config.yaml`)
|
|
219
|
+
|
|
220
|
+
The `config.yaml` file controls the application's behavior:
|
|
221
|
+
|
|
222
|
+
- `llm`: Defines the LLM provider to use and its specific settings. Set the `provider` key to one of the supported names below:
|
|
223
|
+
- `provider: ollama`
|
|
224
|
+
- `ollama_model_name`: (Required) The name of the model served by Ollama (e.g., `gemma3:12b-it-qat`).
|
|
225
|
+
- `ollama_use_chat_model`: (Optional, boolean, default: `true`) Whether to use Ollama's chat completion endpoint.
|
|
226
|
+
- `ollama_parameters`: (Optional) Advanced parameters for fine-tuning model behavior. See [Advanced LLM Configuration](advanced-llm-configuration.md) for details.
|
|
227
|
+
- `provider: llama_cpp_server`
|
|
228
|
+
- `llama_cpp_server_binary`: (Optional) Path to the `llama-server` executable (needed if `auto_start` is true).
|
|
229
|
+
- `llama_cpp_server_args`: (Optional, list) Arguments to pass when auto-starting the server (e.g., model path, host, port).
|
|
230
|
+
- `llama_cpp_server_host`: (Required) Hostname or IP address of the running llama.cpp server (e.g., `127.0.0.1`).
|
|
231
|
+
- `llama_cpp_server_port`: (Required) Port number of the running llama.cpp server (e.g., `5000`).
|
|
232
|
+
- `llama_cpp_server_auto_start`: (Optional, boolean, default: `false`) Whether Argentic should try to start the `llama-server` process itself.
|
|
233
|
+
- `llama_cpp_server_parameters`: (Optional) Advanced parameters for HTTP requests. See [Advanced LLM Configuration](advanced-llm-configuration.md) for details.
|
|
234
|
+
- `provider: llama_cpp_cli`
|
|
235
|
+
- `llama_cpp_cli_binary`: (Required) Path to the `llama.cpp` main CLI executable (e.g., `~/llama.cpp/build/bin/llama-gemma3-cli`).
|
|
236
|
+
- `llama_cpp_cli_model_path`: (Required) Path to the GGUF model file.
|
|
237
|
+
- `llama_cpp_cli_args`: (Optional, list) Additional arguments to pass to the CLI (e.g., `--temp 0.7`, `--n-predict 128`).
|
|
238
|
+
- `llama_cpp_cli_parameters`: (Optional) Advanced parameters automatically converted to CLI arguments. See [Advanced LLM Configuration](advanced-llm-configuration.md) for details.
|
|
239
|
+
- `provider: google_gemini`
|
|
240
|
+
- `google_gemini_api_key`: (Required) Your Google Gemini API key. **It is strongly recommended to set this via the `GOOGLE_GEMINI_API_KEY` environment variable instead of directly in the file.** Argentic uses `python-dotenv` to load variables from a `.env` file.
|
|
241
|
+
- `google_gemini_model_name`: (Required) The specific Gemini model to use (e.g., `gemini-2.0-flash`).
|
|
242
|
+
- `google_gemini_parameters`: (Optional) Advanced parameters including safety settings and structured output. See [Advanced LLM Configuration](advanced-llm-configuration.md) for details.
|
|
243
|
+
|
|
244
|
+
### Advanced LLM Configuration
|
|
245
|
+
|
|
246
|
+
For detailed information about fine-tuning LLM parameters for performance, quality, and behavior, see the [Advanced LLM Configuration Guide](advanced-llm-configuration.md). This includes:
|
|
247
|
+
|
|
248
|
+
- Provider-specific parameter reference
|
|
249
|
+
- Performance vs quality trade-offs
|
|
250
|
+
- GPU acceleration settings
|
|
251
|
+
- Memory optimization techniques
|
|
252
|
+
- Example configurations for different use cases
|
|
253
|
+
- Troubleshooting guide
|
|
254
|
+
|
|
255
|
+
## Tools
|
|
256
|
+
|
|
257
|
+
Argentic supports interaction with external tools via the configured messaging system. Tools run as independent services and communicate with the main agent.
|
|
258
|
+
|
|
259
|
+
**Tool Registration Process:**
|
|
260
|
+
|
|
261
|
+
1. **Tool-Side (`BaseTool`):**
|
|
262
|
+
- A tool service (like `rag_tool_service.py`) instantiates a tool class derived from `core.tools.tool_base.BaseTool`.
|
|
263
|
+
- It calls the `tool.register()` method, providing the relevant messaging topics from the configuration (`register`, `status`, `call`, `response_base`).
|
|
264
|
+
- The tool publishes a `RegisterToolMessage` (containing its name, description/manual, and Pydantic schema for arguments) to the agent's registration topic (e.g., `agent/tools/register`).
|
|
265
|
+
- The tool simultaneously subscribes to the agent's status topic (e.g., `agent/status/info`) to await a `ToolRegisteredMessage` confirmation.
|
|
266
|
+
2. **Agent-Side (`ToolManager`):**
|
|
267
|
+
- The `ToolManager` (within the main agent) listens on the registration topic.
|
|
268
|
+
- Upon receiving a `RegisterToolMessage`, it generates a unique `tool_id` for the tool.
|
|
269
|
+
- It stores the tool's metadata (ID, name, description, API schema).
|
|
270
|
+
- The `ToolManager` subscribes to the tool's specific result topic (e.g., `agent/tools/response/<generated_tool_id>`) to listen for task outcomes.
|
|
271
|
+
- It publishes the `ToolRegisteredMessage` (including the `tool_id`) back to the agent's status topic, confirming registration with the tool.
|
|
272
|
+
3. **Tool-Side (Confirmation):**
|
|
273
|
+
- The tool receives the `ToolRegisteredMessage`, stores its assigned `tool_id`.
|
|
274
|
+
- It then subscribes to its dedicated task topic (e.g., `agent/tools/call/<generated_tool_id>`) to listen for incoming tasks.
|
|
275
|
+
|
|
276
|
+
**Task Execution Flow:**
|
|
277
|
+
|
|
278
|
+
1. **Agent Needs Tool:** The agent (likely prompted by the LLM) decides to use a tool.
|
|
279
|
+
2. **Agent Executes Task (`ToolManager.execute_tool`):**
|
|
280
|
+
- The agent calls `tool_manager.execute_tool(tool_name_or_id, arguments)`.
|
|
281
|
+
- The `ToolManager` creates a `TaskMessage` (containing a unique `task_id`, the `tool_id`, and the arguments).
|
|
282
|
+
- It publishes this `TaskMessage` to the specific tool's task topic (e.g., `agent/tools/call/<tool_id>`).
|
|
283
|
+
- It waits asynchronously for a response message associated with the `task_id` on the tool's result topic.
|
|
284
|
+
3. **Tool Executes Task (`BaseTool._handle_task_message`):**
|
|
285
|
+
- The tool service receives the `TaskMessage` on its task topic.
|
|
286
|
+
- It validates the arguments using the tool's Pydantic schema.
|
|
287
|
+
- It executes the tool's core logic (`_execute` method).
|
|
288
|
+
- It creates a `TaskResultMessage` (on success) or `TaskErrorMessage` (on failure), including the original `task_id`.
|
|
289
|
+
- It publishes this result message to its result topic (e.g., `agent/tools/response/<tool_id>`).
|
|
290
|
+
4. **Agent Receives Result (`ToolManager._handle_result_message`):**
|
|
291
|
+
- The `ToolManager` receives the result message on the tool's result topic.
|
|
292
|
+
- It matches the `task_id` to the pending asynchronous task and delivers the result (or error) back to the agent's logic that initiated the call.
|
|
293
|
+
|
|
294
|
+
An example `rag_tool_service.py` demonstrates how a tool (`KnowledgeBaseTool`) can be built and run independently, registering and communicating with the agent using this messaging pattern.
|
|
295
|
+
|
|
296
|
+
## Testing
|
|
297
|
+
|
|
298
|
+
The project includes a comprehensive test suite organized into categories:
|
|
299
|
+
|
|
300
|
+
### Test Structure
|
|
301
|
+
|
|
302
|
+
- **Unit Tests**: Located in `tests/core/messager/unit/`, these tests verify individual components in isolation.
|
|
303
|
+
- **Integration Tests**: Located in `tests/core/messager/test_messager_integration.py`, these tests verify how components work together.
|
|
304
|
+
- **End-to-End Tests**: Located in `tests/core/messager/e2e/`, these tests verify the system behavior using actual message brokers via Docker.
|
|
305
|
+
|
|
306
|
+
### Running Tests
|
|
307
|
+
|
|
308
|
+
Several scripts are available in the `bin/` directory to run different types of tests:
|
|
309
|
+
|
|
310
|
+
- **All Tests**: Run the complete test suite with the main test script:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
./bin/run_tests.sh
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
- **Unit Tests Only**: Run only the unit tests:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
./bin/run_unit_tests.sh
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
- **E2E Tests Only**: Run only the end-to-end tests (requires Docker):
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
./bin/run_e2e_tests.sh
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
The E2E test script supports Docker container management:
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
# Start Docker containers before running tests
|
|
332
|
+
./bin/run_e2e_tests.sh --start-docker
|
|
333
|
+
|
|
334
|
+
# Start Docker, run tests, and stop containers afterward
|
|
335
|
+
./bin/run_e2e_tests.sh --start-docker --stop-docker
|
|
336
|
+
|
|
337
|
+
# Only start Docker containers without running tests
|
|
338
|
+
./bin/run_e2e_tests.sh --docker-only --start-docker
|
|
339
|
+
|
|
340
|
+
# Only stop Docker containers
|
|
341
|
+
./bin/run_e2e_tests.sh --docker-only --stop-docker
|
|
342
|
+
|
|
343
|
+
# Pass additional arguments to pytest after --
|
|
344
|
+
./bin/run_e2e_tests.sh --start-docker -- -v
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
- **Integration Tests Only**: Run only the integration tests:
|
|
348
|
+
```bash
|
|
349
|
+
./bin/run_integration_tests.sh
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Each script accepts additional pytest arguments. For example, to run tests with higher verbosity:
|
|
353
|
+
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
```
|