lightweight-agent 0.1.4__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.
- lightweight_agent-0.1.4/LICENSE +22 -0
- lightweight_agent-0.1.4/MANIFEST.in +7 -0
- lightweight_agent-0.1.4/PKG-INFO +542 -0
- lightweight_agent-0.1.4/README.md +499 -0
- lightweight_agent-0.1.4/pyproject.toml +71 -0
- lightweight_agent-0.1.4/setup.cfg +4 -0
- lightweight_agent-0.1.4/src/lightweight_agent/__init__.py +53 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/__init__.py +23 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/extension/citation_agent.py +255 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/extension/figure_agent.py +318 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/extension/matplotlib_fix_agent.py +287 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/extension/polish_agent.py +233 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/extension/proposal_agent.py +347 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/message.py +5 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/pretty_print.py +173 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/prompt_builder.py +227 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/react_agent.py +410 -0
- lightweight_agent-0.1.4/src/lightweight_agent/agent/todo_based_agent.py +140 -0
- lightweight_agent-0.1.4/src/lightweight_agent/clients/__init__.py +12 -0
- lightweight_agent-0.1.4/src/lightweight_agent/clients/anthropic_client.py +164 -0
- lightweight_agent-0.1.4/src/lightweight_agent/clients/base.py +27 -0
- lightweight_agent-0.1.4/src/lightweight_agent/clients/openai_client.py +132 -0
- lightweight_agent-0.1.4/src/lightweight_agent/exceptions.py +27 -0
- lightweight_agent-0.1.4/src/lightweight_agent/models.py +80 -0
- lightweight_agent-0.1.4/src/lightweight_agent/session/__init__.py +6 -0
- lightweight_agent-0.1.4/src/lightweight_agent/session/history.py +124 -0
- lightweight_agent-0.1.4/src/lightweight_agent/session/session.py +160 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/__init__.py +6 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/base.py +74 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/__init__.py +14 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/batch_edit_tool.py +198 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/create_todo_list_tool.py +275 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/edit_tool.py +124 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/list_dir_tool.py +155 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/read_tool.py +117 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/run_node_file_tool.py +148 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/run_python_file_tool.py +124 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/save_important_artifacts_tool.py +374 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/update_todo_status_tool.py +105 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/builtin/write_tool.py +157 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/__init__.py +6 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/citation/__init__.py +7 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/citation/bibtex_extract_tool.py +92 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/citation/bibtex_insert_tool.py +114 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/citation/bibtex_save_tool.py +91 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/citation/citaion_engine.py +262 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/citation/example_usage.py +54 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/skill/__init__.py +7 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/skill/skill_registry.py +171 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/skill/skill_tool.py +139 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/vision/__init__.py +5 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/extensions/vision/vision_tool.py +328 -0
- lightweight_agent-0.1.4/src/lightweight_agent/tools/registry.py +65 -0
- lightweight_agent-0.1.4/src/lightweight_agent/utils.py +185 -0
- lightweight_agent-0.1.4/src/lightweight_agent.egg-info/PKG-INFO +542 -0
- lightweight_agent-0.1.4/src/lightweight_agent.egg-info/SOURCES.txt +57 -0
- lightweight_agent-0.1.4/src/lightweight_agent.egg-info/dependency_links.txt +1 -0
- lightweight_agent-0.1.4/src/lightweight_agent.egg-info/requires.txt +17 -0
- lightweight_agent-0.1.4/src/lightweight_agent.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lightweight Agent Contributors
|
|
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.
|
|
22
|
+
|
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lightweight-agent
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: A lightweight LLM agent framework supporting async OpenAI and Anthropic APIs with ReAct agents, TODO-based agents, and built-in tools
|
|
5
|
+
Author: Lightweight Agent Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mbt1909432/lightweight-agent
|
|
8
|
+
Project-URL: Documentation, https://github.com/mbt1909432/lightweight-agent#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/mbt1909432/lightweight-agent
|
|
10
|
+
Project-URL: Issues, https://github.com/mbt1909432/lightweight-agent/issues
|
|
11
|
+
Keywords: llm,openai,anthropic,async,streaming,ai,agent,react,todo
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: openai>=1.0.0
|
|
27
|
+
Requires-Dist: anthropic>=0.18.0
|
|
28
|
+
Requires-Dist: httpx>=0.27.2
|
|
29
|
+
Requires-Dist: rich>=13.0.0
|
|
30
|
+
Requires-Dist: PyYAML>=6.0
|
|
31
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
32
|
+
Requires-Dist: numpy>=1.24.0
|
|
33
|
+
Requires-Dist: seaborn>=0.12.0
|
|
34
|
+
Requires-Dist: plotly>=5.14.0
|
|
35
|
+
Requires-Dist: pandas>=2.0.0
|
|
36
|
+
Requires-Dist: pillow>=10.0.0
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
40
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# Lightweight Agent
|
|
45
|
+
|
|
46
|
+
A lightweight LLM agent framework supporting async OpenAI and Anthropic APIs with streaming/non-streaming responses, built-in ReAct agents and TODO-based agents.
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
- ✅ Async OpenAI and Anthropic API support
|
|
51
|
+
- ✅ Streaming and non-streaming responses
|
|
52
|
+
- ✅ Built-in ReAct Agent and TODO-based Agent
|
|
53
|
+
- ✅ Specialized Agent Extensions (Citation Agent, Figure Agent)
|
|
54
|
+
- ✅ Rich built-in tools (file operations, Python execution, batch editing, etc.)
|
|
55
|
+
- ✅ Citation tools for BibTeX processing
|
|
56
|
+
- ✅ Environment variable configuration support
|
|
57
|
+
- ✅ Unified interface design
|
|
58
|
+
- ✅ Comprehensive error handling
|
|
59
|
+
- ✅ Published to PyPI, supports pip installation
|
|
60
|
+
- ✅ Skill extension and Node.js script runner tools
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
### Install from PyPI (Recommended)
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install lightweight-agent
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Install from Source
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Clone repository
|
|
74
|
+
git clone https://github.com/mbt1909432/lightweight-agent.git
|
|
75
|
+
cd lightweight-agent
|
|
76
|
+
|
|
77
|
+
# Install dependencies
|
|
78
|
+
pip install -e .
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Development Installation
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install -e ".[dev]"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Quick Start
|
|
88
|
+
|
|
89
|
+
### Environment Variables Configuration
|
|
90
|
+
|
|
91
|
+
Before using, you need to set the corresponding environment variables:
|
|
92
|
+
|
|
93
|
+
**OpenAI Configuration:**
|
|
94
|
+
```bash
|
|
95
|
+
export OPENAI_API_KEY="your-openai-api-key"
|
|
96
|
+
export OPENAI_BASE_URL="https://api.openai.com/v1" # Optional
|
|
97
|
+
export OPENAI_MODEL="gpt-3.5-turbo" # Optional, defaults to gpt-3.5-turbo
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Anthropic Configuration:**
|
|
101
|
+
```bash
|
|
102
|
+
export ANTHROPIC_API_KEY="your-anthropic-api-key"
|
|
103
|
+
export ANTHROPIC_BASE_URL="https://api.anthropic.com" # Optional
|
|
104
|
+
export ANTHROPIC_MODEL="claude-3-sonnet-20240229" # Optional, defaults to claude-3-sonnet-20240229
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Basic Usage
|
|
108
|
+
|
|
109
|
+
#### OpenAI Non-streaming Response
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import asyncio
|
|
113
|
+
from lightweight_agent import OpenAIClient
|
|
114
|
+
|
|
115
|
+
async def main():
|
|
116
|
+
client = OpenAIClient()
|
|
117
|
+
response = await client.generate("Hello, how are you?")
|
|
118
|
+
print(response)
|
|
119
|
+
|
|
120
|
+
asyncio.run(main())
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### OpenAI Streaming Response
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
import asyncio
|
|
127
|
+
from lightweight_agent import OpenAIClient
|
|
128
|
+
|
|
129
|
+
async def main():
|
|
130
|
+
client = OpenAIClient()
|
|
131
|
+
async for chunk in await client.generate("Tell me a story", stream=True):
|
|
132
|
+
print(chunk, end="", flush=True)
|
|
133
|
+
print() # New line
|
|
134
|
+
|
|
135
|
+
asyncio.run(main())
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Anthropic Non-streaming Response
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
import asyncio
|
|
142
|
+
from lightweight_agent import AnthropicClient
|
|
143
|
+
|
|
144
|
+
async def main():
|
|
145
|
+
client = AnthropicClient()
|
|
146
|
+
response = await client.generate("Hello, how are you?", max_tokens=1024)
|
|
147
|
+
print(response)
|
|
148
|
+
|
|
149
|
+
asyncio.run(main())
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Anthropic Streaming Response
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
import asyncio
|
|
156
|
+
from lightweight_agent import AnthropicClient
|
|
157
|
+
|
|
158
|
+
async def main():
|
|
159
|
+
client = AnthropicClient()
|
|
160
|
+
async for chunk in await client.generate("Tell me a story", stream=True, max_tokens=1024):
|
|
161
|
+
print(chunk, end="", flush=True)
|
|
162
|
+
print() # New line
|
|
163
|
+
|
|
164
|
+
asyncio.run(main())
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Runtime Configuration
|
|
168
|
+
|
|
169
|
+
You can also pass configuration parameters when initializing the client. These parameters will override environment variables:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from lightweight_agent import OpenAIClient
|
|
173
|
+
|
|
174
|
+
client = OpenAIClient(
|
|
175
|
+
api_key="your-api-key",
|
|
176
|
+
base_url="https://api.openai.com/v1",
|
|
177
|
+
model="gpt-4"
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Advanced Parameters
|
|
182
|
+
|
|
183
|
+
The `generate` method supports passing additional API parameters:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
# OpenAI example
|
|
187
|
+
response = await client.generate(
|
|
188
|
+
"Write a poem",
|
|
189
|
+
stream=False,
|
|
190
|
+
temperature=0.7,
|
|
191
|
+
max_tokens=500
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
# Anthropic example
|
|
195
|
+
response = await client.generate(
|
|
196
|
+
"Write a poem",
|
|
197
|
+
stream=False,
|
|
198
|
+
max_tokens=500,
|
|
199
|
+
temperature=0.7
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## API Documentation
|
|
204
|
+
|
|
205
|
+
### OpenAIClient
|
|
206
|
+
|
|
207
|
+
#### `__init__(api_key=None, base_url=None, model=None)`
|
|
208
|
+
|
|
209
|
+
Initialize OpenAI client.
|
|
210
|
+
|
|
211
|
+
**Parameters:**
|
|
212
|
+
- `api_key` (str, optional): OpenAI API key
|
|
213
|
+
- `base_url` (str, optional): API base URL
|
|
214
|
+
- `model` (str, optional): Model name
|
|
215
|
+
|
|
216
|
+
#### `generate(prompt, stream=False, **kwargs)`
|
|
217
|
+
|
|
218
|
+
Generate response.
|
|
219
|
+
|
|
220
|
+
**Parameters:**
|
|
221
|
+
- `prompt` (str): Prompt text
|
|
222
|
+
- `stream` (bool): Whether to stream response, defaults to False
|
|
223
|
+
- `**kwargs`: Other OpenAI API parameters (e.g., temperature, max_tokens, etc.)
|
|
224
|
+
|
|
225
|
+
**Returns:**
|
|
226
|
+
- If `stream=False`, returns `str`
|
|
227
|
+
- If `stream=True`, returns `AsyncIterator[str]`
|
|
228
|
+
|
|
229
|
+
### AnthropicClient
|
|
230
|
+
|
|
231
|
+
#### `__init__(api_key=None, base_url=None, model=None)`
|
|
232
|
+
|
|
233
|
+
Initialize Anthropic client.
|
|
234
|
+
|
|
235
|
+
**Parameters:**
|
|
236
|
+
- `api_key` (str, optional): Anthropic API key
|
|
237
|
+
- `base_url` (str, optional): API base URL
|
|
238
|
+
- `model` (str, optional): Model name
|
|
239
|
+
|
|
240
|
+
#### `generate(prompt, stream=False, **kwargs)`
|
|
241
|
+
|
|
242
|
+
Generate response.
|
|
243
|
+
|
|
244
|
+
**Parameters:**
|
|
245
|
+
- `prompt` (str): Prompt text
|
|
246
|
+
- `stream` (bool): Whether to stream response, defaults to False
|
|
247
|
+
- `**kwargs`: Other Anthropic API parameters (e.g., max_tokens, temperature, etc.)
|
|
248
|
+
- Note: `max_tokens` is a required parameter for Anthropic API. If not provided, the default value is 1024
|
|
249
|
+
|
|
250
|
+
**Returns:**
|
|
251
|
+
- If `stream=False`, returns `str`
|
|
252
|
+
- If `stream=True`, returns `AsyncIterator[str]`
|
|
253
|
+
|
|
254
|
+
## Exception Handling
|
|
255
|
+
|
|
256
|
+
The library provides the following exception classes:
|
|
257
|
+
|
|
258
|
+
- `LLMClientError`: Base exception class
|
|
259
|
+
- `ConfigurationError`: Configuration error
|
|
260
|
+
- `APIError`: API call error
|
|
261
|
+
- `NetworkError`: Network error
|
|
262
|
+
- `ValidationError`: Validation error
|
|
263
|
+
|
|
264
|
+
Usage example:
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from lightweight_agent import OpenAIClient, ConfigurationError, APIError
|
|
268
|
+
|
|
269
|
+
try:
|
|
270
|
+
client = OpenAIClient()
|
|
271
|
+
response = await client.generate("Hello")
|
|
272
|
+
except ConfigurationError as e:
|
|
273
|
+
print(f"Configuration error: {e}")
|
|
274
|
+
except APIError as e:
|
|
275
|
+
print(f"API error: {e}")
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Agent Usage
|
|
279
|
+
|
|
280
|
+
### ReAct Agent
|
|
281
|
+
|
|
282
|
+
ReAct Agent is an intelligent agent based on reasoning and action that can automatically call tools to complete tasks.
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
import asyncio
|
|
286
|
+
from lightweight_agent import ReActAgent, OpenAIClient
|
|
287
|
+
import os
|
|
288
|
+
from pathlib import Path
|
|
289
|
+
|
|
290
|
+
async def main():
|
|
291
|
+
# Initialize client
|
|
292
|
+
client = OpenAIClient(
|
|
293
|
+
api_key=os.getenv("LLM_API_KEY"),
|
|
294
|
+
base_url=os.getenv("LLM_API_BASE"),
|
|
295
|
+
model=os.getenv("MODEL")
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
# Create agent
|
|
299
|
+
agent = ReActAgent(
|
|
300
|
+
client=client,
|
|
301
|
+
working_dir="./agent_work"
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
# Run task
|
|
305
|
+
async for message in agent.run("Create a text file and write content"):
|
|
306
|
+
# Process message stream
|
|
307
|
+
print(message)
|
|
308
|
+
|
|
309
|
+
asyncio.run(main())
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### TODO-based Agent
|
|
313
|
+
|
|
314
|
+
TODO-based Agent can automatically create task lists and execute them step by step.
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
import asyncio
|
|
318
|
+
from lightweight_agent import TodoBasedAgent, OpenAIClient
|
|
319
|
+
import os
|
|
320
|
+
|
|
321
|
+
async def main():
|
|
322
|
+
client = OpenAIClient(
|
|
323
|
+
api_key=os.getenv("LLM_API_KEY"),
|
|
324
|
+
base_url=os.getenv("LLM_API_BASE"),
|
|
325
|
+
model=os.getenv("MODEL")
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
agent = TodoBasedAgent(
|
|
329
|
+
client=client,
|
|
330
|
+
working_dir="./todo_work"
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
async for message in agent.run("Create a chart using matplotlib"):
|
|
334
|
+
print(message)
|
|
335
|
+
|
|
336
|
+
# View TODO summary
|
|
337
|
+
summary = agent.get_todo_summary()
|
|
338
|
+
print(f"Completed: {summary['completed']}/{summary['total']}")
|
|
339
|
+
|
|
340
|
+
asyncio.run(main())
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Citation Agent
|
|
344
|
+
|
|
345
|
+
Citation Agent is specialized for inserting BibTeX citations into LaTeX documents. It automatically extracts BibTeX entries from source files and inserts them at semantically appropriate locations.
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
import asyncio
|
|
349
|
+
from lightweight_agent import CitationAgent, OpenAIClient
|
|
350
|
+
import os
|
|
351
|
+
|
|
352
|
+
async def main():
|
|
353
|
+
client = OpenAIClient(
|
|
354
|
+
api_key=os.getenv("LLM_API_KEY"),
|
|
355
|
+
base_url=os.getenv("LLM_API_BASE"),
|
|
356
|
+
model=os.getenv("MODEL")
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
agent = CitationAgent(
|
|
360
|
+
client=client,
|
|
361
|
+
working_dir="./citation_work"
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
async for message in agent.run("Extract BibTeX entries from references.txt and insert them into paper.tex"):
|
|
365
|
+
print(message)
|
|
366
|
+
|
|
367
|
+
# View TODO summary
|
|
368
|
+
summary = agent.get_todo_summary()
|
|
369
|
+
print(f"Completed: {summary['completed']}/{summary['total']}")
|
|
370
|
+
|
|
371
|
+
asyncio.run(main())
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### Figure Agent
|
|
375
|
+
|
|
376
|
+
Figure Agent is specialized for inserting figures into LaTeX documents. It scans figure directories and automatically inserts figures at semantically appropriate locations.
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
import asyncio
|
|
380
|
+
from lightweight_agent import FigureAgent, OpenAIClient
|
|
381
|
+
import os
|
|
382
|
+
|
|
383
|
+
async def main():
|
|
384
|
+
client = OpenAIClient(
|
|
385
|
+
api_key=os.getenv("LLM_API_KEY"),
|
|
386
|
+
base_url=os.getenv("LLM_API_BASE"),
|
|
387
|
+
model=os.getenv("MODEL")
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
agent = FigureAgent(
|
|
391
|
+
client=client,
|
|
392
|
+
working_dir="./figure_work"
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
async for message in agent.run("Insert all figures from the figure directory into paper.tex"):
|
|
396
|
+
print(message)
|
|
397
|
+
|
|
398
|
+
# View TODO summary
|
|
399
|
+
summary = agent.get_todo_summary()
|
|
400
|
+
print(f"Completed: {summary['completed']}/{summary['total']}")
|
|
401
|
+
|
|
402
|
+
asyncio.run(main())
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
For more Agent usage examples, see [`Use_Case/README.md`](Use_Case/README.md).
|
|
406
|
+
|
|
407
|
+
## Example Code
|
|
408
|
+
|
|
409
|
+
For more example code, see:
|
|
410
|
+
|
|
411
|
+
- `examples/` directory - Basic client usage examples
|
|
412
|
+
- `examples/openai_streaming.py` - OpenAI streaming response example
|
|
413
|
+
- `examples/openai_non_streaming.py` - OpenAI non-streaming response example
|
|
414
|
+
- `examples/anthropic_streaming.py` - Anthropic streaming response example
|
|
415
|
+
- `examples/anthropic_non_streaming.py` - Anthropic non-streaming response example
|
|
416
|
+
- `examples/citation_agent/` - Citation Agent usage example
|
|
417
|
+
- `examples/citation_agent/example.py` - Citation Agent example
|
|
418
|
+
- `examples/citation_agent/README.md` - Citation Agent documentation
|
|
419
|
+
- `Use_Case/` directory - Agent usage examples
|
|
420
|
+
- `Use_Case/base_agent_example.py` - ReAct Agent example
|
|
421
|
+
- `Use_Case/todo_agent_example.py` - TODO-based Agent example
|
|
422
|
+
- `Use_Case/citation_agent_example.py` - Citation Agent example
|
|
423
|
+
|
|
424
|
+
## Development
|
|
425
|
+
|
|
426
|
+
### Run Tests
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
pytest tests/
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Code Formatting
|
|
433
|
+
|
|
434
|
+
```bash
|
|
435
|
+
black src/ tests/ examples/
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### Code Linting
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
ruff check src/ tests/ examples/
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
## License
|
|
445
|
+
|
|
446
|
+
MIT License
|
|
447
|
+
|
|
448
|
+
## Contributing
|
|
449
|
+
|
|
450
|
+
Issues and Pull Requests are welcome!
|
|
451
|
+
|
|
452
|
+
## Changelog
|
|
453
|
+
|
|
454
|
+
### 0.1.0 (2025-01-01)
|
|
455
|
+
|
|
456
|
+
- Initial release
|
|
457
|
+
- Support for async OpenAI and Anthropic APIs
|
|
458
|
+
- Support for streaming and non-streaming responses
|
|
459
|
+
- Environment variable configuration support
|
|
460
|
+
- Built-in ReAct Agent and TODO-based Agent
|
|
461
|
+
- Rich built-in tool support
|
|
462
|
+
|
|
463
|
+
### 0.2.0 (2025-01-10)
|
|
464
|
+
|
|
465
|
+
- Added Citation Agent extension for BibTeX citation insertion
|
|
466
|
+
- Added Figure Agent extension for LaTeX figure insertion
|
|
467
|
+
- Added BatchEditTool for efficient batch file editing
|
|
468
|
+
- Added Citation tools (bibtex_extract, bibtex_insert, bibtex_save)
|
|
469
|
+
- Enhanced TODO-based Agent with specialized workflows
|
|
470
|
+
|
|
471
|
+
### 0.1.4 (2026-01-20)
|
|
472
|
+
|
|
473
|
+
- Added Skill extension (`SkillTool`) with registry support for reusable skills
|
|
474
|
+
- Added Node.js runner tool for executing local `.js` files inside the agent
|
|
475
|
+
- Synchronized version documentation and packaging metadata
|
|
476
|
+
|
|
477
|
+
## Version Updates
|
|
478
|
+
|
|
479
|
+
The project has been published to [PyPI](https://pypi.org/project/lightweight-agent/). To update versions:
|
|
480
|
+
|
|
481
|
+
### 1. Update Version Number
|
|
482
|
+
|
|
483
|
+
You need to update the version number in two files:
|
|
484
|
+
|
|
485
|
+
**`pyproject.toml`**:
|
|
486
|
+
```toml
|
|
487
|
+
[project]
|
|
488
|
+
version = "0.1.4" # Update version number
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
**`src/lightweight_agent/__init__.py`**:
|
|
492
|
+
```python
|
|
493
|
+
__version__ = "0.1.4" # Update version number
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
### 2. Build New Version
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
# Clean old builds
|
|
500
|
+
rm -rf build dist *.egg-info # Linux/Mac
|
|
501
|
+
# Or PowerShell
|
|
502
|
+
Remove-Item -Recurse -Force build, dist, *.egg-info -ErrorAction SilentlyContinue
|
|
503
|
+
|
|
504
|
+
# Build new package
|
|
505
|
+
python -m build
|
|
506
|
+
|
|
507
|
+
# Validate package
|
|
508
|
+
twine check dist/*
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### 3. Publish to PyPI
|
|
512
|
+
|
|
513
|
+
```bash
|
|
514
|
+
# Upload to PyPI
|
|
515
|
+
twine upload dist/*
|
|
516
|
+
|
|
517
|
+
# Or use environment variables to set authentication
|
|
518
|
+
export TWINE_USERNAME="__token__"
|
|
519
|
+
export TWINE_PASSWORD="pypi-your-api-token"
|
|
520
|
+
twine upload dist/*
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### 4. Verify Release
|
|
524
|
+
|
|
525
|
+
```bash
|
|
526
|
+
# Wait a few minutes, then test installation
|
|
527
|
+
pip install --upgrade lightweight-agent
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
For detailed packaging and publishing process, refer to [`PACKAGING.md`](PACKAGING.md).
|
|
531
|
+
|
|
532
|
+
### Version Numbering Convention
|
|
533
|
+
|
|
534
|
+
Follow [Semantic Versioning](https://semver.org/):
|
|
535
|
+
- **MAJOR version**: Incompatible API changes
|
|
536
|
+
- **MINOR version**: Backward-compatible functionality additions
|
|
537
|
+
- **PATCH version**: Backward-compatible bug fixes
|
|
538
|
+
|
|
539
|
+
Examples:
|
|
540
|
+
- `0.1.0` → `0.1.1` (PATCH: bug fix)
|
|
541
|
+
- `0.1.0` → `0.2.0` (MINOR: new feature)
|
|
542
|
+
- `0.1.0` → `1.0.0` (MAJOR: breaking change)
|