grasp_agents 0.1.15__tar.gz → 0.1.17__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.
- grasp_agents-0.1.17/PKG-INFO +212 -0
- grasp_agents-0.1.17/README.md +196 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/pyproject.toml +2 -2
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/agent_message.py +0 -1
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/base_agent.py +1 -1
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/cloud_llm.py +83 -40
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/comm_agent.py +40 -49
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/llm.py +6 -6
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/llm_agent.py +81 -63
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/memory.py +0 -6
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/openai/completion_converters.py +4 -3
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/openai/converters.py +2 -8
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/openai/message_converters.py +1 -6
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/openai/openai_llm.py +4 -6
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/openai/tool_converters.py +1 -1
- {grasp_agents-0.1.15/src/grasp_agents/data_retrieval → grasp_agents-0.1.17/src/grasp_agents/rate_limiting}/rate_limiter_chunked.py +2 -9
- {grasp_agents-0.1.15/src/grasp_agents/data_retrieval → grasp_agents-0.1.17/src/grasp_agents/rate_limiting}/utils.py +15 -5
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/tool_orchestrator.py +2 -2
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/typing/converters.py +2 -10
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/typing/io.py +1 -4
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/typing/message.py +5 -3
- grasp_agents-0.1.17/src/grasp_agents/typing/tool.py +59 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/utils.py +114 -65
- grasp_agents-0.1.15/PKG-INFO +0 -152
- grasp_agents-0.1.15/README.md +0 -137
- grasp_agents-0.1.15/src/grasp_agents/typing/tool.py +0 -52
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/.gitignore +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/LICENSE.md +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/agent_message_pool.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/costs_dict.yaml +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/grasp_logging.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/http_client.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/llm_agent_state.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/openai/__init__.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/openai/content_converters.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/printer.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/prompt_builder.py +0 -0
- {grasp_agents-0.1.15/src/grasp_agents/data_retrieval → grasp_agents-0.1.17/src/grasp_agents/rate_limiting}/__init__.py +0 -0
- {grasp_agents-0.1.15/src/grasp_agents/data_retrieval → grasp_agents-0.1.17/src/grasp_agents/rate_limiting}/types.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/run_context.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/typing/__init__.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/typing/completion.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/typing/content.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/usage_tracker.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/workflow/__init__.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/workflow/looped_agent.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/workflow/sequential_agent.py +0 -0
- {grasp_agents-0.1.15 → grasp_agents-0.1.17}/src/grasp_agents/workflow/workflow_agent.py +0 -0
@@ -0,0 +1,212 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: grasp_agents
|
3
|
+
Version: 0.1.17
|
4
|
+
Summary: Grasp Agents Library
|
5
|
+
License-File: LICENSE.md
|
6
|
+
Requires-Python: <4,>=3.11.4
|
7
|
+
Requires-Dist: dotenv>=0.9.9
|
8
|
+
Requires-Dist: httpx<1,>=0.27.0
|
9
|
+
Requires-Dist: openai<2,>=1.68.2
|
10
|
+
Requires-Dist: pydantic>=2
|
11
|
+
Requires-Dist: pyyaml>=6.0.2
|
12
|
+
Requires-Dist: tenacity>=9.1.2
|
13
|
+
Requires-Dist: termcolor<3,>=2.4.0
|
14
|
+
Requires-Dist: tqdm<5,>=4.66.2
|
15
|
+
Description-Content-Type: text/markdown
|
16
|
+
|
17
|
+
# Grasp Agents
|
18
|
+
|
19
|
+
<br/>
|
20
|
+
<img src="./.assets/grasp.svg" alt="Grasp Agents" width="320" />
|
21
|
+
<br/>
|
22
|
+
<br/>
|
23
|
+
|
24
|
+
[](https://badge.fury.io/py/grasp-agents)
|
25
|
+
[](https://mit-license.org/)
|
26
|
+
[](https://pypi.org/project/grasp-agents/)
|
27
|
+
[](https://github.com/grasp-technologies/grasp-agents/stargazers)
|
28
|
+
[](https://github.com/grasp-technologies/grasp-agents/network/members)
|
29
|
+
|
30
|
+
## Overview
|
31
|
+
|
32
|
+
**Grasp Agents** is a modular Python framework for building agentic AI pipelines and applications. It is meant to be minimalistic but functional, allowing for rapid experimentation while keeping full and granular low-level control over prompting, LLM handling, and inter-agent communication by avoiding excessive higher-level abstractions.
|
33
|
+
|
34
|
+
## Features
|
35
|
+
|
36
|
+
- Clean formulation of agents as generic entities over:
|
37
|
+
* I/O schemas
|
38
|
+
* Agent state
|
39
|
+
* Shared context
|
40
|
+
- Transparent implementation of common agentic patterns:
|
41
|
+
* Single-agent loops with an optional "ReAct mode" to enforce reasoning between the tool calls
|
42
|
+
* Workflows (static communication topology), including loops
|
43
|
+
* Agents-as-tools for task delegation
|
44
|
+
* Freeform A2A communication via in-process Actor model
|
45
|
+
- Batch processing support outside of agentic loops
|
46
|
+
- Simple logging and usage/cost tracking
|
47
|
+
|
48
|
+
## Project Structure
|
49
|
+
|
50
|
+
- `base_agent.py`, `llm_agent.py`, `comm_agent.py`: Core agent class implementations.
|
51
|
+
- `agent_message.py`, `agent_message_pool.py`: Messaging and message pool management.
|
52
|
+
- `llm_agent_state.py`: State management for LLM agents.
|
53
|
+
- `tool_orchestrator.py`: Orchestration of tools used by agents.
|
54
|
+
- `prompt_builder.py`: Tools for constructing prompts.
|
55
|
+
- `workflow/`: Modules for defining and managing agent workflows.
|
56
|
+
- `cloud_llm.py`, `llm.py`: LLM integration and base LLM functionalities.
|
57
|
+
- `openai/`: Modules specific to OpenAI API integration.
|
58
|
+
- `memory.py`: Memory management for agents (currently only message history).
|
59
|
+
- `run_context.py`: Context management for agent runs.
|
60
|
+
- `usage_tracker.py`: Tracking of API usage and costs.
|
61
|
+
- `costs_dict.yaml`: Dictionary for cost tracking (update if needed).
|
62
|
+
- `rate_limiting/`: Basic rate limiting tools.
|
63
|
+
|
64
|
+
## Quickstart & Installation Variants (UV Package manager)
|
65
|
+
|
66
|
+
> **Note:** You can check this sample project code in the [src/grasp_agents/examples/demo/uv](src/grasp_agents/examples/demo/uv) folder. Feel free to copy and paste the code from there to a separate project. There are also [examples](src/grasp_agents/examples/demo/) for other package managers.
|
67
|
+
|
68
|
+
#### 1. Prerequisites
|
69
|
+
|
70
|
+
Install the [UV Package Manager](https://github.com/astral-sh/uv):
|
71
|
+
|
72
|
+
```bash
|
73
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
74
|
+
```
|
75
|
+
|
76
|
+
#### 2. Create Project & Install Dependencies
|
77
|
+
|
78
|
+
```bash
|
79
|
+
mkdir my-test-uv-app
|
80
|
+
cd my-test-uv-app
|
81
|
+
uv init .
|
82
|
+
```
|
83
|
+
|
84
|
+
Create and activate a virtual environment:
|
85
|
+
|
86
|
+
```bash
|
87
|
+
uv venv
|
88
|
+
source .venv/bin/activate
|
89
|
+
```
|
90
|
+
|
91
|
+
Add and sync dependencies:
|
92
|
+
|
93
|
+
```bash
|
94
|
+
uv add grasp_agents
|
95
|
+
uv sync
|
96
|
+
```
|
97
|
+
|
98
|
+
#### 3. Example Usage
|
99
|
+
|
100
|
+
Ensure you have a `.env` file with your OpenAI and Google AI Studio API keys set
|
101
|
+
|
102
|
+
```
|
103
|
+
OPENAI_API_KEY=your_openai_api_key
|
104
|
+
GOOGLE_AI_STUDIO_API_KEY=your_google_ai_studio_api_key
|
105
|
+
```
|
106
|
+
|
107
|
+
Create a script, e.g., `problem_recommender.py`:
|
108
|
+
|
109
|
+
```python
|
110
|
+
import re
|
111
|
+
from typing import Any
|
112
|
+
from pathlib import Path
|
113
|
+
from pydantic import BaseModel, Field
|
114
|
+
from dotenv import load_dotenv
|
115
|
+
from grasp_agents.typing.tool import BaseTool
|
116
|
+
from grasp_agents.typing.io import AgentPayload
|
117
|
+
from grasp_agents.run_context import RunContextWrapper
|
118
|
+
from grasp_agents.openai.openai_llm import OpenAILLM, OpenAILLMSettings
|
119
|
+
from grasp_agents.llm_agent import LLMAgent
|
120
|
+
from grasp_agents.grasp_logging import setup_logging
|
121
|
+
from grasp_agents.typing.message import Conversation
|
122
|
+
|
123
|
+
load_dotenv()
|
124
|
+
|
125
|
+
|
126
|
+
# Configure the logger to output to the console and/or a file
|
127
|
+
setup_logging(
|
128
|
+
logs_file_path="grasp_agents_demo.log",
|
129
|
+
logs_config_path=Path().cwd() / "configs/logging/default.yaml",
|
130
|
+
)
|
131
|
+
|
132
|
+
sys_prompt_react = """
|
133
|
+
Your task is to suggest an exciting stats problem to a student.
|
134
|
+
Ask the student about their education, interests, and preferences, then suggest a problem tailored to them.
|
135
|
+
|
136
|
+
# Instructions
|
137
|
+
* Ask questions one by one.
|
138
|
+
* Provide your thinking before asking a question and after receiving a reply.
|
139
|
+
* The problem must be enclosed in <PROBLEM> tags.
|
140
|
+
"""
|
141
|
+
|
142
|
+
|
143
|
+
class TeacherQuestion(BaseModel):
|
144
|
+
question: str = Field(..., description="The question to ask the student.")
|
145
|
+
|
146
|
+
StudentReply = str
|
147
|
+
|
148
|
+
|
149
|
+
class AskStudentTool(BaseTool[TeacherQuestion, StudentReply, Any]):
|
150
|
+
name: str = "ask_student_tool"
|
151
|
+
description: str = "Ask the student a question and get their reply."
|
152
|
+
in_schema: type[TeacherQuestion] = TeacherQuestion
|
153
|
+
out_schema: type[StudentReply] = StudentReply
|
154
|
+
|
155
|
+
async def run(
|
156
|
+
self, inp: TeacherQuestion, ctx: RunContextWrapper[Any] | None = None
|
157
|
+
) -> StudentReply:
|
158
|
+
return input(inp.question)
|
159
|
+
|
160
|
+
|
161
|
+
class FinalResponse(AgentPayload):
|
162
|
+
problem: str
|
163
|
+
|
164
|
+
|
165
|
+
teacher = LLMAgent[Any, FinalResponse, None](
|
166
|
+
agent_id="teacher",
|
167
|
+
llm=OpenAILLM(
|
168
|
+
model_name="gpt-4.1",
|
169
|
+
api_provider="openai",
|
170
|
+
llm_settings=OpenAILLMSettings(temperature=0.1),
|
171
|
+
),
|
172
|
+
tools=[AskStudentTool()],
|
173
|
+
max_turns=20,
|
174
|
+
react_mode=True,
|
175
|
+
sys_prompt=sys_prompt_react,
|
176
|
+
out_schema=FinalResponse,
|
177
|
+
set_state_strategy="reset",
|
178
|
+
)
|
179
|
+
|
180
|
+
|
181
|
+
@teacher.tool_call_loop_exit_handler
|
182
|
+
def exit_tool_call_loop(conversation: Conversation, ctx, **kwargs) -> None:
|
183
|
+
message_text = conversation[-1].content
|
184
|
+
|
185
|
+
return re.search(r"<PROBLEM>", message_text)
|
186
|
+
|
187
|
+
|
188
|
+
@teacher.parse_output_handler
|
189
|
+
def parse_output(conversation: Conversation, ctx, **kwargs) -> FinalResponse:
|
190
|
+
message_text = conversation[-1].content
|
191
|
+
matches = re.findall(r"<PROBLEM>(.*?)</PROBLEM>", message_text, re.DOTALL)
|
192
|
+
|
193
|
+
return FinalResponse(problem=matches[0])
|
194
|
+
|
195
|
+
|
196
|
+
async def main():
|
197
|
+
ctx = RunContextWrapper(print_messages=True)
|
198
|
+
out = await teacher.run(ctx=ctx)
|
199
|
+
print(out.payloads[0].problem)
|
200
|
+
print(ctx.usage_tracker.total_usage)
|
201
|
+
|
202
|
+
|
203
|
+
asyncio.run(main())
|
204
|
+
```
|
205
|
+
|
206
|
+
Run your script:
|
207
|
+
|
208
|
+
```bash
|
209
|
+
uv run problem_recommender.py
|
210
|
+
```
|
211
|
+
|
212
|
+
You can find more examples in [src/grasp_agents/examples/notebooks/agents_demo.ipynb](src/grasp_agents/examples/notebooks/agents_demo.ipynb).
|
@@ -0,0 +1,196 @@
|
|
1
|
+
# Grasp Agents
|
2
|
+
|
3
|
+
<br/>
|
4
|
+
<img src="./.assets/grasp.svg" alt="Grasp Agents" width="320" />
|
5
|
+
<br/>
|
6
|
+
<br/>
|
7
|
+
|
8
|
+
[](https://badge.fury.io/py/grasp-agents)
|
9
|
+
[](https://mit-license.org/)
|
10
|
+
[](https://pypi.org/project/grasp-agents/)
|
11
|
+
[](https://github.com/grasp-technologies/grasp-agents/stargazers)
|
12
|
+
[](https://github.com/grasp-technologies/grasp-agents/network/members)
|
13
|
+
|
14
|
+
## Overview
|
15
|
+
|
16
|
+
**Grasp Agents** is a modular Python framework for building agentic AI pipelines and applications. It is meant to be minimalistic but functional, allowing for rapid experimentation while keeping full and granular low-level control over prompting, LLM handling, and inter-agent communication by avoiding excessive higher-level abstractions.
|
17
|
+
|
18
|
+
## Features
|
19
|
+
|
20
|
+
- Clean formulation of agents as generic entities over:
|
21
|
+
* I/O schemas
|
22
|
+
* Agent state
|
23
|
+
* Shared context
|
24
|
+
- Transparent implementation of common agentic patterns:
|
25
|
+
* Single-agent loops with an optional "ReAct mode" to enforce reasoning between the tool calls
|
26
|
+
* Workflows (static communication topology), including loops
|
27
|
+
* Agents-as-tools for task delegation
|
28
|
+
* Freeform A2A communication via in-process Actor model
|
29
|
+
- Batch processing support outside of agentic loops
|
30
|
+
- Simple logging and usage/cost tracking
|
31
|
+
|
32
|
+
## Project Structure
|
33
|
+
|
34
|
+
- `base_agent.py`, `llm_agent.py`, `comm_agent.py`: Core agent class implementations.
|
35
|
+
- `agent_message.py`, `agent_message_pool.py`: Messaging and message pool management.
|
36
|
+
- `llm_agent_state.py`: State management for LLM agents.
|
37
|
+
- `tool_orchestrator.py`: Orchestration of tools used by agents.
|
38
|
+
- `prompt_builder.py`: Tools for constructing prompts.
|
39
|
+
- `workflow/`: Modules for defining and managing agent workflows.
|
40
|
+
- `cloud_llm.py`, `llm.py`: LLM integration and base LLM functionalities.
|
41
|
+
- `openai/`: Modules specific to OpenAI API integration.
|
42
|
+
- `memory.py`: Memory management for agents (currently only message history).
|
43
|
+
- `run_context.py`: Context management for agent runs.
|
44
|
+
- `usage_tracker.py`: Tracking of API usage and costs.
|
45
|
+
- `costs_dict.yaml`: Dictionary for cost tracking (update if needed).
|
46
|
+
- `rate_limiting/`: Basic rate limiting tools.
|
47
|
+
|
48
|
+
## Quickstart & Installation Variants (UV Package manager)
|
49
|
+
|
50
|
+
> **Note:** You can check this sample project code in the [src/grasp_agents/examples/demo/uv](src/grasp_agents/examples/demo/uv) folder. Feel free to copy and paste the code from there to a separate project. There are also [examples](src/grasp_agents/examples/demo/) for other package managers.
|
51
|
+
|
52
|
+
#### 1. Prerequisites
|
53
|
+
|
54
|
+
Install the [UV Package Manager](https://github.com/astral-sh/uv):
|
55
|
+
|
56
|
+
```bash
|
57
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
58
|
+
```
|
59
|
+
|
60
|
+
#### 2. Create Project & Install Dependencies
|
61
|
+
|
62
|
+
```bash
|
63
|
+
mkdir my-test-uv-app
|
64
|
+
cd my-test-uv-app
|
65
|
+
uv init .
|
66
|
+
```
|
67
|
+
|
68
|
+
Create and activate a virtual environment:
|
69
|
+
|
70
|
+
```bash
|
71
|
+
uv venv
|
72
|
+
source .venv/bin/activate
|
73
|
+
```
|
74
|
+
|
75
|
+
Add and sync dependencies:
|
76
|
+
|
77
|
+
```bash
|
78
|
+
uv add grasp_agents
|
79
|
+
uv sync
|
80
|
+
```
|
81
|
+
|
82
|
+
#### 3. Example Usage
|
83
|
+
|
84
|
+
Ensure you have a `.env` file with your OpenAI and Google AI Studio API keys set
|
85
|
+
|
86
|
+
```
|
87
|
+
OPENAI_API_KEY=your_openai_api_key
|
88
|
+
GOOGLE_AI_STUDIO_API_KEY=your_google_ai_studio_api_key
|
89
|
+
```
|
90
|
+
|
91
|
+
Create a script, e.g., `problem_recommender.py`:
|
92
|
+
|
93
|
+
```python
|
94
|
+
import re
|
95
|
+
from typing import Any
|
96
|
+
from pathlib import Path
|
97
|
+
from pydantic import BaseModel, Field
|
98
|
+
from dotenv import load_dotenv
|
99
|
+
from grasp_agents.typing.tool import BaseTool
|
100
|
+
from grasp_agents.typing.io import AgentPayload
|
101
|
+
from grasp_agents.run_context import RunContextWrapper
|
102
|
+
from grasp_agents.openai.openai_llm import OpenAILLM, OpenAILLMSettings
|
103
|
+
from grasp_agents.llm_agent import LLMAgent
|
104
|
+
from grasp_agents.grasp_logging import setup_logging
|
105
|
+
from grasp_agents.typing.message import Conversation
|
106
|
+
|
107
|
+
load_dotenv()
|
108
|
+
|
109
|
+
|
110
|
+
# Configure the logger to output to the console and/or a file
|
111
|
+
setup_logging(
|
112
|
+
logs_file_path="grasp_agents_demo.log",
|
113
|
+
logs_config_path=Path().cwd() / "configs/logging/default.yaml",
|
114
|
+
)
|
115
|
+
|
116
|
+
sys_prompt_react = """
|
117
|
+
Your task is to suggest an exciting stats problem to a student.
|
118
|
+
Ask the student about their education, interests, and preferences, then suggest a problem tailored to them.
|
119
|
+
|
120
|
+
# Instructions
|
121
|
+
* Ask questions one by one.
|
122
|
+
* Provide your thinking before asking a question and after receiving a reply.
|
123
|
+
* The problem must be enclosed in <PROBLEM> tags.
|
124
|
+
"""
|
125
|
+
|
126
|
+
|
127
|
+
class TeacherQuestion(BaseModel):
|
128
|
+
question: str = Field(..., description="The question to ask the student.")
|
129
|
+
|
130
|
+
StudentReply = str
|
131
|
+
|
132
|
+
|
133
|
+
class AskStudentTool(BaseTool[TeacherQuestion, StudentReply, Any]):
|
134
|
+
name: str = "ask_student_tool"
|
135
|
+
description: str = "Ask the student a question and get their reply."
|
136
|
+
in_schema: type[TeacherQuestion] = TeacherQuestion
|
137
|
+
out_schema: type[StudentReply] = StudentReply
|
138
|
+
|
139
|
+
async def run(
|
140
|
+
self, inp: TeacherQuestion, ctx: RunContextWrapper[Any] | None = None
|
141
|
+
) -> StudentReply:
|
142
|
+
return input(inp.question)
|
143
|
+
|
144
|
+
|
145
|
+
class FinalResponse(AgentPayload):
|
146
|
+
problem: str
|
147
|
+
|
148
|
+
|
149
|
+
teacher = LLMAgent[Any, FinalResponse, None](
|
150
|
+
agent_id="teacher",
|
151
|
+
llm=OpenAILLM(
|
152
|
+
model_name="gpt-4.1",
|
153
|
+
api_provider="openai",
|
154
|
+
llm_settings=OpenAILLMSettings(temperature=0.1),
|
155
|
+
),
|
156
|
+
tools=[AskStudentTool()],
|
157
|
+
max_turns=20,
|
158
|
+
react_mode=True,
|
159
|
+
sys_prompt=sys_prompt_react,
|
160
|
+
out_schema=FinalResponse,
|
161
|
+
set_state_strategy="reset",
|
162
|
+
)
|
163
|
+
|
164
|
+
|
165
|
+
@teacher.tool_call_loop_exit_handler
|
166
|
+
def exit_tool_call_loop(conversation: Conversation, ctx, **kwargs) -> None:
|
167
|
+
message_text = conversation[-1].content
|
168
|
+
|
169
|
+
return re.search(r"<PROBLEM>", message_text)
|
170
|
+
|
171
|
+
|
172
|
+
@teacher.parse_output_handler
|
173
|
+
def parse_output(conversation: Conversation, ctx, **kwargs) -> FinalResponse:
|
174
|
+
message_text = conversation[-1].content
|
175
|
+
matches = re.findall(r"<PROBLEM>(.*?)</PROBLEM>", message_text, re.DOTALL)
|
176
|
+
|
177
|
+
return FinalResponse(problem=matches[0])
|
178
|
+
|
179
|
+
|
180
|
+
async def main():
|
181
|
+
ctx = RunContextWrapper(print_messages=True)
|
182
|
+
out = await teacher.run(ctx=ctx)
|
183
|
+
print(out.payloads[0].problem)
|
184
|
+
print(ctx.usage_tracker.total_usage)
|
185
|
+
|
186
|
+
|
187
|
+
asyncio.run(main())
|
188
|
+
```
|
189
|
+
|
190
|
+
Run your script:
|
191
|
+
|
192
|
+
```bash
|
193
|
+
uv run problem_recommender.py
|
194
|
+
```
|
195
|
+
|
196
|
+
You can find more examples in [src/grasp_agents/examples/notebooks/agents_demo.ipynb](src/grasp_agents/examples/notebooks/agents_demo.ipynb).
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "grasp_agents"
|
3
|
-
version = "0.1.
|
3
|
+
version = "0.1.17"
|
4
4
|
description = "Grasp Agents Library"
|
5
5
|
readme = "README.md"
|
6
6
|
requires-python = ">=3.11.4,<4"
|
@@ -12,6 +12,7 @@ dependencies = [
|
|
12
12
|
"tqdm>=4.66.2,<5",
|
13
13
|
"dotenv>=0.9.9",
|
14
14
|
"pyyaml>=6.0.2",
|
15
|
+
"pydantic>=2",
|
15
16
|
]
|
16
17
|
|
17
18
|
[dependency-groups]
|
@@ -22,7 +23,6 @@ dev = [
|
|
22
23
|
"ipywidgets>=8.0.4,<9",
|
23
24
|
"widgetsnbextension>=4.0.5,<5",
|
24
25
|
"types-cachetools>=5.0.1,<6",
|
25
|
-
"pydantic>=2",
|
26
26
|
"pre-commit-uv>=4.1.4",
|
27
27
|
"twine>=5.1.1,<6",
|
28
28
|
"ruff>=0.11.8",
|