aixtools 0.1.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.
Potentially problematic release.
This version of aixtools might be problematic. Click here for more details.
- aixtools-0.1.0/PKG-INFO +355 -0
- aixtools-0.1.0/README.md +328 -0
- aixtools-0.1.0/aixtools/__init__.py +5 -0
- aixtools-0.1.0/aixtools/a2a/__init__.py +5 -0
- aixtools-0.1.0/aixtools/a2a/app.py +126 -0
- aixtools-0.1.0/aixtools/a2a/utils.py +115 -0
- aixtools-0.1.0/aixtools/agents/__init__.py +12 -0
- aixtools-0.1.0/aixtools/agents/agent.py +164 -0
- aixtools-0.1.0/aixtools/agents/agent_batch.py +74 -0
- aixtools-0.1.0/aixtools/app.py +143 -0
- aixtools-0.1.0/aixtools/context.py +12 -0
- aixtools-0.1.0/aixtools/db/__init__.py +17 -0
- aixtools-0.1.0/aixtools/db/database.py +110 -0
- aixtools-0.1.0/aixtools/db/vector_db.py +115 -0
- aixtools-0.1.0/aixtools/log_view/__init__.py +17 -0
- aixtools-0.1.0/aixtools/log_view/app.py +195 -0
- aixtools-0.1.0/aixtools/log_view/display.py +285 -0
- aixtools-0.1.0/aixtools/log_view/export.py +51 -0
- aixtools-0.1.0/aixtools/log_view/filters.py +41 -0
- aixtools-0.1.0/aixtools/log_view/log_utils.py +26 -0
- aixtools-0.1.0/aixtools/log_view/node_summary.py +229 -0
- aixtools-0.1.0/aixtools/logfilters/__init__.py +7 -0
- aixtools-0.1.0/aixtools/logfilters/context_filter.py +67 -0
- aixtools-0.1.0/aixtools/logging/__init__.py +30 -0
- aixtools-0.1.0/aixtools/logging/log_objects.py +227 -0
- aixtools-0.1.0/aixtools/logging/logging_config.py +116 -0
- aixtools-0.1.0/aixtools/logging/mcp_log_models.py +102 -0
- aixtools-0.1.0/aixtools/logging/mcp_logger.py +172 -0
- aixtools-0.1.0/aixtools/logging/model_patch_logging.py +87 -0
- aixtools-0.1.0/aixtools/logging/open_telemetry.py +36 -0
- aixtools-0.1.0/aixtools/mcp/__init__.py +9 -0
- aixtools-0.1.0/aixtools/mcp/example_client.py +30 -0
- aixtools-0.1.0/aixtools/mcp/example_server.py +22 -0
- aixtools-0.1.0/aixtools/mcp/fast_mcp_log.py +31 -0
- aixtools-0.1.0/aixtools/mcp/faulty_mcp.py +320 -0
- aixtools-0.1.0/aixtools/model_patch/model_patch.py +65 -0
- aixtools-0.1.0/aixtools/server/__init__.py +23 -0
- aixtools-0.1.0/aixtools/server/app_mounter.py +90 -0
- aixtools-0.1.0/aixtools/server/path.py +72 -0
- aixtools-0.1.0/aixtools/server/utils.py +70 -0
- aixtools-0.1.0/aixtools/testing/__init__.py +9 -0
- aixtools-0.1.0/aixtools/testing/aix_test_model.py +147 -0
- aixtools-0.1.0/aixtools/testing/mock_tool.py +66 -0
- aixtools-0.1.0/aixtools/testing/model_patch_cache.py +279 -0
- aixtools-0.1.0/aixtools/tools/doctor/__init__.py +3 -0
- aixtools-0.1.0/aixtools/tools/doctor/tool_doctor.py +61 -0
- aixtools-0.1.0/aixtools/tools/doctor/tool_recommendation.py +44 -0
- aixtools-0.1.0/aixtools/utils/__init__.py +35 -0
- aixtools-0.1.0/aixtools/utils/chainlit/cl_agent_show.py +82 -0
- aixtools-0.1.0/aixtools/utils/chainlit/cl_utils.py +168 -0
- aixtools-0.1.0/aixtools/utils/config.py +118 -0
- aixtools-0.1.0/aixtools/utils/config_util.py +69 -0
- aixtools-0.1.0/aixtools/utils/enum_with_description.py +37 -0
- aixtools-0.1.0/aixtools/utils/persisted_dict.py +99 -0
- aixtools-0.1.0/aixtools/utils/utils.py +160 -0
- aixtools-0.1.0/aixtools.egg-info/PKG-INFO +355 -0
- aixtools-0.1.0/aixtools.egg-info/SOURCES.txt +61 -0
- aixtools-0.1.0/aixtools.egg-info/dependency_links.txt +1 -0
- aixtools-0.1.0/aixtools.egg-info/entry_points.txt +2 -0
- aixtools-0.1.0/aixtools.egg-info/requires.txt +22 -0
- aixtools-0.1.0/aixtools.egg-info/top_level.txt +6 -0
- aixtools-0.1.0/pyproject.toml +58 -0
- aixtools-0.1.0/setup.cfg +4 -0
aixtools-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aixtools
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tools for AI exploration and debugging
|
|
5
|
+
Requires-Python: >=3.11.2
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: chainlit>=2.5.5
|
|
8
|
+
Requires-Dist: colorlog>=6.9.0
|
|
9
|
+
Requires-Dist: fasta2a>=0.5.0
|
|
10
|
+
Requires-Dist: fastmcp>=2.10.2
|
|
11
|
+
Requires-Dist: ipykernel>=6.29.5
|
|
12
|
+
Requires-Dist: langchain-chroma>=0.2.3
|
|
13
|
+
Requires-Dist: langchain-ollama>=0.3.2
|
|
14
|
+
Requires-Dist: langchain-openai>=0.3.14
|
|
15
|
+
Requires-Dist: mcp>=1.11.0
|
|
16
|
+
Requires-Dist: pandas>=2.2.3
|
|
17
|
+
Requires-Dist: pydantic-ai>=0.4.10
|
|
18
|
+
Requires-Dist: pylint>=3.3.7
|
|
19
|
+
Requires-Dist: rich>=14.0.0
|
|
20
|
+
Requires-Dist: ruff>=0.11.6
|
|
21
|
+
Requires-Dist: streamlit>=1.44.1
|
|
22
|
+
Requires-Dist: watchdog>=6.0.0
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pyyaml; extra == "test"
|
|
25
|
+
Provides-Extra: feature
|
|
26
|
+
Requires-Dist: logfire; extra == "feature"
|
|
27
|
+
|
|
28
|
+
# AiXplore-tools
|
|
29
|
+
|
|
30
|
+
AiXplore-tools (`axitools` for short) is a Python library to support AI agent development and debugging. It serves two main purposes:
|
|
31
|
+
|
|
32
|
+
1. **Utility Library**: A collection of utility functions and classes for agent projects
|
|
33
|
+
2. **Debugging Tool**: A Streamlit app (`log_view`) for visualizing and debugging agent applications by viewing messages logged by `ObjectLogger`
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## `.venv`
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
# Create a new environment
|
|
40
|
+
uv venv .venv
|
|
41
|
+
source .venv/bin/activate
|
|
42
|
+
|
|
43
|
+
# Add packages
|
|
44
|
+
uv add pydantic-ai
|
|
45
|
+
uv add mcp[cli]
|
|
46
|
+
uv add chainlit
|
|
47
|
+
uv add streamlit
|
|
48
|
+
|
|
49
|
+
# Add langchain
|
|
50
|
+
uv add langchain-chroma
|
|
51
|
+
uv add langchain-ollama
|
|
52
|
+
uv add langchain-openai
|
|
53
|
+
|
|
54
|
+
# Other packages
|
|
55
|
+
uv add colorlog
|
|
56
|
+
uv add pandas
|
|
57
|
+
uv add rich
|
|
58
|
+
uv add ruff
|
|
59
|
+
uv add watchdog
|
|
60
|
+
uv add ipykernel
|
|
61
|
+
|
|
62
|
+
# Install this code as a package
|
|
63
|
+
uv pip install -e .
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
Installing the package from GitHub, you can use `uv add` (prefered)
|
|
69
|
+
```
|
|
70
|
+
uv add https://github.com/your-org/aixtools.git
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
or using the `pip` commamnd
|
|
74
|
+
```
|
|
75
|
+
uv pip install https://github.com/your-org/aixtools.git
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Remember to set up your [`.env` file](#environment-configuration).
|
|
79
|
+
|
|
80
|
+
### Updating
|
|
81
|
+
|
|
82
|
+
This package is in active development and changes often.
|
|
83
|
+
|
|
84
|
+
You'll want to force uv to re-install or update it to the latest commit, even if the version hasn’t changed.
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
uv add --upgrade https://github.com/your-org/aixtools.git
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Example: Creatng a new project
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
# Create a new project
|
|
94
|
+
uv init MyNewProject
|
|
95
|
+
cd MyNewProject
|
|
96
|
+
|
|
97
|
+
# Add a virtual environemnt and activate it
|
|
98
|
+
uv venv .venv
|
|
99
|
+
source .venv/bin/activate
|
|
100
|
+
|
|
101
|
+
# Add this package
|
|
102
|
+
uv add https://github.com/your-org/aixtools.git
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Environment Configuration
|
|
106
|
+
|
|
107
|
+
AIXtools requires specific environment variables to be set for proper operation, especially when working with different model providers.
|
|
108
|
+
|
|
109
|
+
Here is a [template of an `.env`](./.env_template) file you can use as reference.
|
|
110
|
+
|
|
111
|
+
#### Setting Up Environment Variables
|
|
112
|
+
|
|
113
|
+
1. Create a `.env` file in your project root based on the template below:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
# Model family (azure, openai, or ollama)
|
|
117
|
+
MODEL_FAMILY=azure
|
|
118
|
+
VDB_EMBEDDINGS_MODEL_FAMILY=azure
|
|
119
|
+
|
|
120
|
+
MODEL_TIMEOUT=120
|
|
121
|
+
|
|
122
|
+
# Azure OpenAI
|
|
123
|
+
AZURE_OPENAI_ENDPOINT=https://your_endpoint.openai.azure.com
|
|
124
|
+
AZURE_OPENAI_API_VERSION=2024-06-01
|
|
125
|
+
AZURE_OPENAI_API_KEY=your_secret_key
|
|
126
|
+
AZURE_MODEL_NAME=gpt-4o
|
|
127
|
+
AZURE_OPENAI_PROVIDER_ID=azure
|
|
128
|
+
AZURE_VDB_EMBEDDINGS_MODEL_NAME=text-embedding-3-small
|
|
129
|
+
|
|
130
|
+
# OpenAI
|
|
131
|
+
OPENAI_MODEL_NAME=gpt-4.5-preview
|
|
132
|
+
OPENAI_API_KEY=openai_api_key
|
|
133
|
+
OPENAI_VDB_EMBEDDINGS_MODEL_NAME=text-embedding-3-small
|
|
134
|
+
|
|
135
|
+
# Ollama models
|
|
136
|
+
OLLAMA_MODEL_NAME=llama3.2:3b-instruct-fp16
|
|
137
|
+
OLLAMA_LOCAL_URL=http://localhost:11434/v1
|
|
138
|
+
OLLAMA_VDB_EMBEDDINGS_MODEL_NAME=snowflake-arctic-embed2:latest
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
2. Configure the variables according to your needs:
|
|
142
|
+
- Set `MODEL_FAMILY` to your preferred model provider (`azure`, `openai`, or `ollama`)
|
|
143
|
+
- Provide the appropriate API keys and endpoints for your chosen provider
|
|
144
|
+
- Adjust model names and timeouts as needed
|
|
145
|
+
|
|
146
|
+
#### Important Environment Variables
|
|
147
|
+
|
|
148
|
+
| Variable | Description | Required |
|
|
149
|
+
|----------|-------------|----------|
|
|
150
|
+
| `MODEL_FAMILY` | The model provider to use (azure, openai, ollama) | Yes |
|
|
151
|
+
| `MODEL_TIMEOUT` | Timeout in seconds for model requests | Yes |
|
|
152
|
+
| `AZURE_*` | Azure OpenAI configuration (if using Azure) | If MODEL_FAMILY=azure |
|
|
153
|
+
| `OPENAI_*` | OpenAI configuration (if using OpenAI) | If MODEL_FAMILY=openai |
|
|
154
|
+
| `OLLAMA_*` | Ollama configuration (if using Ollama) | If MODEL_FAMILY=ollama |
|
|
155
|
+
|
|
156
|
+
## Debugging tools: `log_view` and `ObjectLogger`
|
|
157
|
+
|
|
158
|
+
The `ObjectLogger` provides a simple logging facility, these logs can then be visualized with `log_view` app.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
### `ObjectLogger`
|
|
162
|
+
|
|
163
|
+
The `ObjectLogger` class allows you to log objects to a file for later analysis. This is particularly useful for debugging agent interactions.
|
|
164
|
+
|
|
165
|
+
`ObjectLogger` simply serializes objects to a pickle file. It first removes unserializeable parts of the objects (e.g. like `async` managers).
|
|
166
|
+
|
|
167
|
+
#### Basic Usage
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from aixtools.utils.log_objects import ObjectLogger
|
|
171
|
+
|
|
172
|
+
# Create a logger as a context manager
|
|
173
|
+
with ObjectLogger() as logger:
|
|
174
|
+
# Log any pickleable object
|
|
175
|
+
logger.log({"message": "Hello, world!"})
|
|
176
|
+
|
|
177
|
+
# Log agent responses or any other objects
|
|
178
|
+
logger.log(agent_response)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Logging Agent Interactions
|
|
182
|
+
|
|
183
|
+
The function `run_agent` logs each node from the agent run, roughtly it looks like this:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
async def run_agent(agent: Agent, prompt: str | list[str]):
|
|
187
|
+
nodes = []
|
|
188
|
+
async with agent.iter(prompt) as agent_run:
|
|
189
|
+
with ObjectLogger(debug=debug) as agent_logger:
|
|
190
|
+
async for node in agent_run:
|
|
191
|
+
agent_logger.log(node)
|
|
192
|
+
nodes.append(node)
|
|
193
|
+
result = agent_run.result
|
|
194
|
+
return result.data, nodes
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Saving Multiple Objects
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from aixtools.utils.log_objects import save_objects_to_logfile
|
|
201
|
+
|
|
202
|
+
# Save a list of objects to a log file
|
|
203
|
+
objects = [obj1, obj2, obj3]
|
|
204
|
+
save_objects_to_logfile(objects)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### log_view App
|
|
208
|
+
|
|
209
|
+
The `log_view` app allows you to visualize and analyze the objects logged by `ObjectLogger`.
|
|
210
|
+
|
|
211
|
+
It is a simple Streamlit app that you can run locally and view the log files.
|
|
212
|
+
|
|
213
|
+
#### Running the App
|
|
214
|
+
|
|
215
|
+
You can run the app using the command-line script installed with the package:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
log_view
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Or specify a custom log directory:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
log_view /path/to/logs
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### Features
|
|
228
|
+
|
|
229
|
+
The log_view app provides several features for analyzing logged objects:
|
|
230
|
+
|
|
231
|
+
- **Log File Selection**: Choose from available log files
|
|
232
|
+
- **Filtering**: Filter nodes by text, type, attributes, or regex patterns
|
|
233
|
+
- **Visualization**: Expand/collapse nodes to view details
|
|
234
|
+
- **Export**: Export filtered nodes to JSON
|
|
235
|
+
|
|
236
|
+
#### Example Workflow
|
|
237
|
+
|
|
238
|
+
1. Log agent interactions using `ObjectLogger`
|
|
239
|
+
2. Run the `log_view` app to analyze the logs
|
|
240
|
+
3. Filter and explore the logged objects
|
|
241
|
+
4. Export interesting findings for further analysis
|
|
242
|
+
|
|
243
|
+
## Additional Utilities
|
|
244
|
+
|
|
245
|
+
AIXtools provides several other utilities to support agent development:
|
|
246
|
+
|
|
247
|
+
### PersistedDict
|
|
248
|
+
|
|
249
|
+
A dictionary that persists to a file on disk as JSON or pickle:
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from aixtools.utils.persisted_dict import PersistedDict
|
|
253
|
+
|
|
254
|
+
# Create a persisted dictionary
|
|
255
|
+
data = PersistedDict("data.json")
|
|
256
|
+
|
|
257
|
+
# Use it like a regular dictionary
|
|
258
|
+
data["key"] = "value" # Automatically saved to disk
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Agent Utilities
|
|
262
|
+
|
|
263
|
+
Functions for creating and running agents with different model providers:
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
from aixtools.agents.agent import get_agent, run_agent
|
|
267
|
+
|
|
268
|
+
# Create an agent with the default model (from MODEL_FAMILY)
|
|
269
|
+
agent = get_agent(system_prompt="You are a helpful assistant.")
|
|
270
|
+
|
|
271
|
+
# Create an agent with a specific model
|
|
272
|
+
from aixtools.agents.agent import get_model_openai
|
|
273
|
+
model = get_model_openai()
|
|
274
|
+
agent = get_agent(system_prompt="You are a helpful assistant.", model=model)
|
|
275
|
+
|
|
276
|
+
# Run the agent
|
|
277
|
+
result, nodes = await run_agent(agent, "Tell me about AI")
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Batch Processing
|
|
281
|
+
|
|
282
|
+
Run multiple agent queries simultaneously:
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
from aixtools.agents.agent_batch import agent_batch, AgentQueryParams
|
|
286
|
+
|
|
287
|
+
# Create query parameters
|
|
288
|
+
query_parameters = [
|
|
289
|
+
AgentQueryParams(prompt="What is the meaning of life"),
|
|
290
|
+
AgentQueryParams(prompt="Who is the prime minister of Canada")
|
|
291
|
+
]
|
|
292
|
+
|
|
293
|
+
# Run queries in batches
|
|
294
|
+
async for result in agent_batch(query_parameters):
|
|
295
|
+
print(result)
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Project Structure
|
|
299
|
+
|
|
300
|
+
```
|
|
301
|
+
aixtools/
|
|
302
|
+
├── __init__.py # Package initialization
|
|
303
|
+
├── log_view.py # Entry point for log_view app
|
|
304
|
+
├── agents/ # Agent-related functionality
|
|
305
|
+
│ ├── agent.py # Core agent functions
|
|
306
|
+
│ └── agent_batch.py # Batch processing for agents
|
|
307
|
+
├── log_view/ # Log viewer application
|
|
308
|
+
│ ├── app.py # Main Streamlit application
|
|
309
|
+
│ ├── display.py # Node display utilities
|
|
310
|
+
│ ├── export.py # Export functionality
|
|
311
|
+
│ ├── filters.py # Node filtering
|
|
312
|
+
│ ├── log_utils.py # Log file utilities
|
|
313
|
+
│ └── node_utils.py # Node processing utilities
|
|
314
|
+
└── utils/ # Utility functions and classes
|
|
315
|
+
├── config.py # Configuration utilities
|
|
316
|
+
├── log_objects.py # Object logging functionality
|
|
317
|
+
├── persisted_dict.py # Persistent dictionary
|
|
318
|
+
└── utils.py # General utilities
|
|
319
|
+
|
|
320
|
+
## Logging
|
|
321
|
+
|
|
322
|
+
The logging system is configured using a standard Python `dictConfig` schema. By default, it will look for a `logging.yaml` or `logging.json` file in your project's root directory. You can also specify a custom path using the `LOGGING_CONFIG_PATH` environment variable.
|
|
323
|
+
|
|
324
|
+
If no configuration file is found, a default colorized console logger will be used.
|
|
325
|
+
|
|
326
|
+
### Example `logging.yaml`
|
|
327
|
+
|
|
328
|
+
```yaml
|
|
329
|
+
version: 1
|
|
330
|
+
disable_existing_loggers: false
|
|
331
|
+
formatters:
|
|
332
|
+
default:
|
|
333
|
+
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
334
|
+
color:
|
|
335
|
+
"()": "colorlog.ColoredFormatter"
|
|
336
|
+
"format": "%(log_color)s%(levelname)-8s%(reset)s [%(name)s] %(message)s"
|
|
337
|
+
handlers:
|
|
338
|
+
console:
|
|
339
|
+
class: colorlog.StreamHandler
|
|
340
|
+
formatter: color
|
|
341
|
+
level: DEBUG
|
|
342
|
+
file:
|
|
343
|
+
class: logging.handlers.RotatingFileHandler
|
|
344
|
+
formatter: default
|
|
345
|
+
filename: app.log
|
|
346
|
+
maxBytes: 10485760 # 10MB
|
|
347
|
+
backupCount: 5
|
|
348
|
+
level: INFO
|
|
349
|
+
root:
|
|
350
|
+
handlers: [console, file]
|
|
351
|
+
level: DEBUG
|
|
352
|
+
loggers:
|
|
353
|
+
aixtools:
|
|
354
|
+
level: INFO
|
|
355
|
+
```
|
aixtools-0.1.0/README.md
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
# AiXplore-tools
|
|
2
|
+
|
|
3
|
+
AiXplore-tools (`axitools` for short) is a Python library to support AI agent development and debugging. It serves two main purposes:
|
|
4
|
+
|
|
5
|
+
1. **Utility Library**: A collection of utility functions and classes for agent projects
|
|
6
|
+
2. **Debugging Tool**: A Streamlit app (`log_view`) for visualizing and debugging agent applications by viewing messages logged by `ObjectLogger`
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## `.venv`
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
# Create a new environment
|
|
13
|
+
uv venv .venv
|
|
14
|
+
source .venv/bin/activate
|
|
15
|
+
|
|
16
|
+
# Add packages
|
|
17
|
+
uv add pydantic-ai
|
|
18
|
+
uv add mcp[cli]
|
|
19
|
+
uv add chainlit
|
|
20
|
+
uv add streamlit
|
|
21
|
+
|
|
22
|
+
# Add langchain
|
|
23
|
+
uv add langchain-chroma
|
|
24
|
+
uv add langchain-ollama
|
|
25
|
+
uv add langchain-openai
|
|
26
|
+
|
|
27
|
+
# Other packages
|
|
28
|
+
uv add colorlog
|
|
29
|
+
uv add pandas
|
|
30
|
+
uv add rich
|
|
31
|
+
uv add ruff
|
|
32
|
+
uv add watchdog
|
|
33
|
+
uv add ipykernel
|
|
34
|
+
|
|
35
|
+
# Install this code as a package
|
|
36
|
+
uv pip install -e .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
Installing the package from GitHub, you can use `uv add` (prefered)
|
|
42
|
+
```
|
|
43
|
+
uv add https://github.com/your-org/aixtools.git
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
or using the `pip` commamnd
|
|
47
|
+
```
|
|
48
|
+
uv pip install https://github.com/your-org/aixtools.git
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Remember to set up your [`.env` file](#environment-configuration).
|
|
52
|
+
|
|
53
|
+
### Updating
|
|
54
|
+
|
|
55
|
+
This package is in active development and changes often.
|
|
56
|
+
|
|
57
|
+
You'll want to force uv to re-install or update it to the latest commit, even if the version hasn’t changed.
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
uv add --upgrade https://github.com/your-org/aixtools.git
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Example: Creatng a new project
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
# Create a new project
|
|
67
|
+
uv init MyNewProject
|
|
68
|
+
cd MyNewProject
|
|
69
|
+
|
|
70
|
+
# Add a virtual environemnt and activate it
|
|
71
|
+
uv venv .venv
|
|
72
|
+
source .venv/bin/activate
|
|
73
|
+
|
|
74
|
+
# Add this package
|
|
75
|
+
uv add https://github.com/your-org/aixtools.git
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Environment Configuration
|
|
79
|
+
|
|
80
|
+
AIXtools requires specific environment variables to be set for proper operation, especially when working with different model providers.
|
|
81
|
+
|
|
82
|
+
Here is a [template of an `.env`](./.env_template) file you can use as reference.
|
|
83
|
+
|
|
84
|
+
#### Setting Up Environment Variables
|
|
85
|
+
|
|
86
|
+
1. Create a `.env` file in your project root based on the template below:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
# Model family (azure, openai, or ollama)
|
|
90
|
+
MODEL_FAMILY=azure
|
|
91
|
+
VDB_EMBEDDINGS_MODEL_FAMILY=azure
|
|
92
|
+
|
|
93
|
+
MODEL_TIMEOUT=120
|
|
94
|
+
|
|
95
|
+
# Azure OpenAI
|
|
96
|
+
AZURE_OPENAI_ENDPOINT=https://your_endpoint.openai.azure.com
|
|
97
|
+
AZURE_OPENAI_API_VERSION=2024-06-01
|
|
98
|
+
AZURE_OPENAI_API_KEY=your_secret_key
|
|
99
|
+
AZURE_MODEL_NAME=gpt-4o
|
|
100
|
+
AZURE_OPENAI_PROVIDER_ID=azure
|
|
101
|
+
AZURE_VDB_EMBEDDINGS_MODEL_NAME=text-embedding-3-small
|
|
102
|
+
|
|
103
|
+
# OpenAI
|
|
104
|
+
OPENAI_MODEL_NAME=gpt-4.5-preview
|
|
105
|
+
OPENAI_API_KEY=openai_api_key
|
|
106
|
+
OPENAI_VDB_EMBEDDINGS_MODEL_NAME=text-embedding-3-small
|
|
107
|
+
|
|
108
|
+
# Ollama models
|
|
109
|
+
OLLAMA_MODEL_NAME=llama3.2:3b-instruct-fp16
|
|
110
|
+
OLLAMA_LOCAL_URL=http://localhost:11434/v1
|
|
111
|
+
OLLAMA_VDB_EMBEDDINGS_MODEL_NAME=snowflake-arctic-embed2:latest
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
2. Configure the variables according to your needs:
|
|
115
|
+
- Set `MODEL_FAMILY` to your preferred model provider (`azure`, `openai`, or `ollama`)
|
|
116
|
+
- Provide the appropriate API keys and endpoints for your chosen provider
|
|
117
|
+
- Adjust model names and timeouts as needed
|
|
118
|
+
|
|
119
|
+
#### Important Environment Variables
|
|
120
|
+
|
|
121
|
+
| Variable | Description | Required |
|
|
122
|
+
|----------|-------------|----------|
|
|
123
|
+
| `MODEL_FAMILY` | The model provider to use (azure, openai, ollama) | Yes |
|
|
124
|
+
| `MODEL_TIMEOUT` | Timeout in seconds for model requests | Yes |
|
|
125
|
+
| `AZURE_*` | Azure OpenAI configuration (if using Azure) | If MODEL_FAMILY=azure |
|
|
126
|
+
| `OPENAI_*` | OpenAI configuration (if using OpenAI) | If MODEL_FAMILY=openai |
|
|
127
|
+
| `OLLAMA_*` | Ollama configuration (if using Ollama) | If MODEL_FAMILY=ollama |
|
|
128
|
+
|
|
129
|
+
## Debugging tools: `log_view` and `ObjectLogger`
|
|
130
|
+
|
|
131
|
+
The `ObjectLogger` provides a simple logging facility, these logs can then be visualized with `log_view` app.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
### `ObjectLogger`
|
|
135
|
+
|
|
136
|
+
The `ObjectLogger` class allows you to log objects to a file for later analysis. This is particularly useful for debugging agent interactions.
|
|
137
|
+
|
|
138
|
+
`ObjectLogger` simply serializes objects to a pickle file. It first removes unserializeable parts of the objects (e.g. like `async` managers).
|
|
139
|
+
|
|
140
|
+
#### Basic Usage
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from aixtools.utils.log_objects import ObjectLogger
|
|
144
|
+
|
|
145
|
+
# Create a logger as a context manager
|
|
146
|
+
with ObjectLogger() as logger:
|
|
147
|
+
# Log any pickleable object
|
|
148
|
+
logger.log({"message": "Hello, world!"})
|
|
149
|
+
|
|
150
|
+
# Log agent responses or any other objects
|
|
151
|
+
logger.log(agent_response)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Logging Agent Interactions
|
|
155
|
+
|
|
156
|
+
The function `run_agent` logs each node from the agent run, roughtly it looks like this:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
async def run_agent(agent: Agent, prompt: str | list[str]):
|
|
160
|
+
nodes = []
|
|
161
|
+
async with agent.iter(prompt) as agent_run:
|
|
162
|
+
with ObjectLogger(debug=debug) as agent_logger:
|
|
163
|
+
async for node in agent_run:
|
|
164
|
+
agent_logger.log(node)
|
|
165
|
+
nodes.append(node)
|
|
166
|
+
result = agent_run.result
|
|
167
|
+
return result.data, nodes
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### Saving Multiple Objects
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from aixtools.utils.log_objects import save_objects_to_logfile
|
|
174
|
+
|
|
175
|
+
# Save a list of objects to a log file
|
|
176
|
+
objects = [obj1, obj2, obj3]
|
|
177
|
+
save_objects_to_logfile(objects)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### log_view App
|
|
181
|
+
|
|
182
|
+
The `log_view` app allows you to visualize and analyze the objects logged by `ObjectLogger`.
|
|
183
|
+
|
|
184
|
+
It is a simple Streamlit app that you can run locally and view the log files.
|
|
185
|
+
|
|
186
|
+
#### Running the App
|
|
187
|
+
|
|
188
|
+
You can run the app using the command-line script installed with the package:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
log_view
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Or specify a custom log directory:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
log_view /path/to/logs
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### Features
|
|
201
|
+
|
|
202
|
+
The log_view app provides several features for analyzing logged objects:
|
|
203
|
+
|
|
204
|
+
- **Log File Selection**: Choose from available log files
|
|
205
|
+
- **Filtering**: Filter nodes by text, type, attributes, or regex patterns
|
|
206
|
+
- **Visualization**: Expand/collapse nodes to view details
|
|
207
|
+
- **Export**: Export filtered nodes to JSON
|
|
208
|
+
|
|
209
|
+
#### Example Workflow
|
|
210
|
+
|
|
211
|
+
1. Log agent interactions using `ObjectLogger`
|
|
212
|
+
2. Run the `log_view` app to analyze the logs
|
|
213
|
+
3. Filter and explore the logged objects
|
|
214
|
+
4. Export interesting findings for further analysis
|
|
215
|
+
|
|
216
|
+
## Additional Utilities
|
|
217
|
+
|
|
218
|
+
AIXtools provides several other utilities to support agent development:
|
|
219
|
+
|
|
220
|
+
### PersistedDict
|
|
221
|
+
|
|
222
|
+
A dictionary that persists to a file on disk as JSON or pickle:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from aixtools.utils.persisted_dict import PersistedDict
|
|
226
|
+
|
|
227
|
+
# Create a persisted dictionary
|
|
228
|
+
data = PersistedDict("data.json")
|
|
229
|
+
|
|
230
|
+
# Use it like a regular dictionary
|
|
231
|
+
data["key"] = "value" # Automatically saved to disk
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Agent Utilities
|
|
235
|
+
|
|
236
|
+
Functions for creating and running agents with different model providers:
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from aixtools.agents.agent import get_agent, run_agent
|
|
240
|
+
|
|
241
|
+
# Create an agent with the default model (from MODEL_FAMILY)
|
|
242
|
+
agent = get_agent(system_prompt="You are a helpful assistant.")
|
|
243
|
+
|
|
244
|
+
# Create an agent with a specific model
|
|
245
|
+
from aixtools.agents.agent import get_model_openai
|
|
246
|
+
model = get_model_openai()
|
|
247
|
+
agent = get_agent(system_prompt="You are a helpful assistant.", model=model)
|
|
248
|
+
|
|
249
|
+
# Run the agent
|
|
250
|
+
result, nodes = await run_agent(agent, "Tell me about AI")
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Batch Processing
|
|
254
|
+
|
|
255
|
+
Run multiple agent queries simultaneously:
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
from aixtools.agents.agent_batch import agent_batch, AgentQueryParams
|
|
259
|
+
|
|
260
|
+
# Create query parameters
|
|
261
|
+
query_parameters = [
|
|
262
|
+
AgentQueryParams(prompt="What is the meaning of life"),
|
|
263
|
+
AgentQueryParams(prompt="Who is the prime minister of Canada")
|
|
264
|
+
]
|
|
265
|
+
|
|
266
|
+
# Run queries in batches
|
|
267
|
+
async for result in agent_batch(query_parameters):
|
|
268
|
+
print(result)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Project Structure
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
aixtools/
|
|
275
|
+
├── __init__.py # Package initialization
|
|
276
|
+
├── log_view.py # Entry point for log_view app
|
|
277
|
+
├── agents/ # Agent-related functionality
|
|
278
|
+
│ ├── agent.py # Core agent functions
|
|
279
|
+
│ └── agent_batch.py # Batch processing for agents
|
|
280
|
+
├── log_view/ # Log viewer application
|
|
281
|
+
│ ├── app.py # Main Streamlit application
|
|
282
|
+
│ ├── display.py # Node display utilities
|
|
283
|
+
│ ├── export.py # Export functionality
|
|
284
|
+
│ ├── filters.py # Node filtering
|
|
285
|
+
│ ├── log_utils.py # Log file utilities
|
|
286
|
+
│ └── node_utils.py # Node processing utilities
|
|
287
|
+
└── utils/ # Utility functions and classes
|
|
288
|
+
├── config.py # Configuration utilities
|
|
289
|
+
├── log_objects.py # Object logging functionality
|
|
290
|
+
├── persisted_dict.py # Persistent dictionary
|
|
291
|
+
└── utils.py # General utilities
|
|
292
|
+
|
|
293
|
+
## Logging
|
|
294
|
+
|
|
295
|
+
The logging system is configured using a standard Python `dictConfig` schema. By default, it will look for a `logging.yaml` or `logging.json` file in your project's root directory. You can also specify a custom path using the `LOGGING_CONFIG_PATH` environment variable.
|
|
296
|
+
|
|
297
|
+
If no configuration file is found, a default colorized console logger will be used.
|
|
298
|
+
|
|
299
|
+
### Example `logging.yaml`
|
|
300
|
+
|
|
301
|
+
```yaml
|
|
302
|
+
version: 1
|
|
303
|
+
disable_existing_loggers: false
|
|
304
|
+
formatters:
|
|
305
|
+
default:
|
|
306
|
+
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
307
|
+
color:
|
|
308
|
+
"()": "colorlog.ColoredFormatter"
|
|
309
|
+
"format": "%(log_color)s%(levelname)-8s%(reset)s [%(name)s] %(message)s"
|
|
310
|
+
handlers:
|
|
311
|
+
console:
|
|
312
|
+
class: colorlog.StreamHandler
|
|
313
|
+
formatter: color
|
|
314
|
+
level: DEBUG
|
|
315
|
+
file:
|
|
316
|
+
class: logging.handlers.RotatingFileHandler
|
|
317
|
+
formatter: default
|
|
318
|
+
filename: app.log
|
|
319
|
+
maxBytes: 10485760 # 10MB
|
|
320
|
+
backupCount: 5
|
|
321
|
+
level: INFO
|
|
322
|
+
root:
|
|
323
|
+
handlers: [console, file]
|
|
324
|
+
level: DEBUG
|
|
325
|
+
loggers:
|
|
326
|
+
aixtools:
|
|
327
|
+
level: INFO
|
|
328
|
+
```
|