agno 1.7.11__py3-none-any.whl → 1.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agno/agent/agent.py +13 -0
- agno/app/agui/utils.py +1 -1
- agno/app/fastapi/async_router.py +13 -10
- agno/embedder/google.py +17 -5
- agno/knowledge/gcs/pdf.py +105 -1
- agno/media.py +24 -3
- agno/models/google/gemini.py +71 -19
- agno/models/openai/chat.py +5 -1
- agno/models/openai/responses.py +26 -9
- agno/reasoning/default.py +7 -1
- agno/reasoning/helpers.py +7 -1
- agno/storage/dynamodb.py +18 -22
- agno/team/team.py +165 -65
- agno/tools/bravesearch.py +7 -7
- agno/tools/calculator.py +8 -8
- agno/tools/discord.py +11 -11
- agno/tools/duckduckgo.py +8 -16
- agno/tools/github.py +26 -14
- agno/tools/memori.py +387 -0
- agno/tools/scrapegraph.py +65 -0
- agno/tools/youtube.py +12 -11
- agno/vectordb/pgvector/pgvector.py +23 -39
- agno/workflow/v2/step.py +4 -0
- agno/workflow/v2/types.py +11 -1
- agno/workflow/v2/workflow.py +54 -1
- {agno-1.7.11.dist-info → agno-1.8.0.dist-info}/METADATA +7 -4
- {agno-1.7.11.dist-info → agno-1.8.0.dist-info}/RECORD +31 -30
- {agno-1.7.11.dist-info → agno-1.8.0.dist-info}/WHEEL +0 -0
- {agno-1.7.11.dist-info → agno-1.8.0.dist-info}/entry_points.txt +0 -0
- {agno-1.7.11.dist-info → agno-1.8.0.dist-info}/licenses/LICENSE +0 -0
- {agno-1.7.11.dist-info → agno-1.8.0.dist-info}/top_level.txt +0 -0
agno/storage/dynamodb.py
CHANGED
|
@@ -30,19 +30,23 @@ class DynamoDbStorage(Storage):
|
|
|
30
30
|
endpoint_url: Optional[str] = None,
|
|
31
31
|
create_table_if_not_exists: bool = True,
|
|
32
32
|
mode: Optional[Literal["agent", "team", "workflow", "workflow_v2"]] = "agent",
|
|
33
|
+
create_table_read_capacity_units: int = 5,
|
|
34
|
+
create_table_write_capacity_units: int = 5,
|
|
33
35
|
):
|
|
34
36
|
"""
|
|
35
37
|
Initialize the DynamoDbStorage.
|
|
36
38
|
|
|
37
39
|
Args:
|
|
38
40
|
table_name (str): The name of the DynamoDB table.
|
|
39
|
-
region_name (Optional[str]): AWS region name.
|
|
40
41
|
profile_name (Optional[str]): AWS profile name to use for credentials.
|
|
42
|
+
region_name (Optional[str]): AWS region name.
|
|
41
43
|
aws_access_key_id (Optional[str]): AWS access key ID.
|
|
42
44
|
aws_secret_access_key (Optional[str]): AWS secret access key.
|
|
43
45
|
endpoint_url (Optional[str]): The complete URL to use for the constructed client.
|
|
44
46
|
create_table_if_not_exists (bool): Whether to create the table if it does not exist.
|
|
45
47
|
mode (Optional[Literal["agent", "team", "workflow", "workflow_v2"]]): The mode of the storage.
|
|
48
|
+
create_table_read_capacity_units Optional[int]: Read capacity units for created table (default: 5).
|
|
49
|
+
create_table_write_capacity_units Optional[int]: Write capacity units for created table (default: 5).
|
|
46
50
|
"""
|
|
47
51
|
super().__init__(mode)
|
|
48
52
|
self.table_name = table_name
|
|
@@ -52,6 +56,8 @@ class DynamoDbStorage(Storage):
|
|
|
52
56
|
self.aws_access_key_id = aws_access_key_id
|
|
53
57
|
self.aws_secret_access_key = aws_secret_access_key
|
|
54
58
|
self.create_table_if_not_exists = create_table_if_not_exists
|
|
59
|
+
self.create_table_read_capacity_units = create_table_read_capacity_units
|
|
60
|
+
self.create_table_write_capacity_units = create_table_write_capacity_units
|
|
55
61
|
|
|
56
62
|
# Create session using profile name if provided
|
|
57
63
|
if self.profile_name:
|
|
@@ -96,6 +102,11 @@ class DynamoDbStorage(Storage):
|
|
|
96
102
|
"""
|
|
97
103
|
Create the DynamoDB table if it does not exist.
|
|
98
104
|
"""
|
|
105
|
+
provisioned_throughput = {
|
|
106
|
+
"ReadCapacityUnits": self.create_table_read_capacity_units,
|
|
107
|
+
"WriteCapacityUnits": self.create_table_write_capacity_units,
|
|
108
|
+
}
|
|
109
|
+
|
|
99
110
|
try:
|
|
100
111
|
# Check if table exists
|
|
101
112
|
self.dynamodb.meta.client.describe_table(TableName=self.table_name)
|
|
@@ -141,10 +152,7 @@ class DynamoDbStorage(Storage):
|
|
|
141
152
|
{"AttributeName": "created_at", "KeyType": "RANGE"},
|
|
142
153
|
],
|
|
143
154
|
"Projection": {"ProjectionType": "ALL"},
|
|
144
|
-
"ProvisionedThroughput":
|
|
145
|
-
"ReadCapacityUnits": 5,
|
|
146
|
-
"WriteCapacityUnits": 5,
|
|
147
|
-
},
|
|
155
|
+
"ProvisionedThroughput": provisioned_throughput,
|
|
148
156
|
}
|
|
149
157
|
]
|
|
150
158
|
if self.mode == "agent":
|
|
@@ -156,10 +164,7 @@ class DynamoDbStorage(Storage):
|
|
|
156
164
|
{"AttributeName": "created_at", "KeyType": "RANGE"},
|
|
157
165
|
],
|
|
158
166
|
"Projection": {"ProjectionType": "ALL"},
|
|
159
|
-
"ProvisionedThroughput":
|
|
160
|
-
"ReadCapacityUnits": 5,
|
|
161
|
-
"WriteCapacityUnits": 5,
|
|
162
|
-
},
|
|
167
|
+
"ProvisionedThroughput": provisioned_throughput,
|
|
163
168
|
}
|
|
164
169
|
)
|
|
165
170
|
elif self.mode == "team":
|
|
@@ -171,10 +176,7 @@ class DynamoDbStorage(Storage):
|
|
|
171
176
|
{"AttributeName": "created_at", "KeyType": "RANGE"},
|
|
172
177
|
],
|
|
173
178
|
"Projection": {"ProjectionType": "ALL"},
|
|
174
|
-
"ProvisionedThroughput":
|
|
175
|
-
"ReadCapacityUnits": 5,
|
|
176
|
-
"WriteCapacityUnits": 5,
|
|
177
|
-
},
|
|
179
|
+
"ProvisionedThroughput": provisioned_throughput,
|
|
178
180
|
}
|
|
179
181
|
)
|
|
180
182
|
elif self.mode == "workflow":
|
|
@@ -186,10 +188,7 @@ class DynamoDbStorage(Storage):
|
|
|
186
188
|
{"AttributeName": "created_at", "KeyType": "RANGE"},
|
|
187
189
|
],
|
|
188
190
|
"Projection": {"ProjectionType": "ALL"},
|
|
189
|
-
"ProvisionedThroughput":
|
|
190
|
-
"ReadCapacityUnits": 5,
|
|
191
|
-
"WriteCapacityUnits": 5,
|
|
192
|
-
},
|
|
191
|
+
"ProvisionedThroughput": provisioned_throughput,
|
|
193
192
|
}
|
|
194
193
|
)
|
|
195
194
|
elif self.mode == "workflow_v2":
|
|
@@ -201,10 +200,7 @@ class DynamoDbStorage(Storage):
|
|
|
201
200
|
{"AttributeName": "created_at", "KeyType": "RANGE"},
|
|
202
201
|
],
|
|
203
202
|
"Projection": {"ProjectionType": "ALL"},
|
|
204
|
-
"ProvisionedThroughput":
|
|
205
|
-
"ReadCapacityUnits": 5,
|
|
206
|
-
"WriteCapacityUnits": 5,
|
|
207
|
-
},
|
|
203
|
+
"ProvisionedThroughput": provisioned_throughput,
|
|
208
204
|
}
|
|
209
205
|
)
|
|
210
206
|
# Create the table
|
|
@@ -213,7 +209,7 @@ class DynamoDbStorage(Storage):
|
|
|
213
209
|
KeySchema=[{"AttributeName": "session_id", "KeyType": "HASH"}],
|
|
214
210
|
AttributeDefinitions=attribute_definitions,
|
|
215
211
|
GlobalSecondaryIndexes=secondary_indexes,
|
|
216
|
-
ProvisionedThroughput=
|
|
212
|
+
ProvisionedThroughput=provisioned_throughput,
|
|
217
213
|
)
|
|
218
214
|
# Wait until the table exists.
|
|
219
215
|
self.table.wait_until_exists()
|
agno/team/team.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
import contextlib
|
|
2
3
|
import json
|
|
3
4
|
from collections import ChainMap, defaultdict, deque
|
|
4
5
|
from copy import deepcopy
|
|
@@ -4503,7 +4504,11 @@ class Team:
|
|
|
4503
4504
|
from agno.reasoning.openai import is_openai_reasoning_model
|
|
4504
4505
|
|
|
4505
4506
|
reasoning_agent = self.reasoning_agent or get_reasoning_agent(
|
|
4506
|
-
reasoning_model=reasoning_model,
|
|
4507
|
+
reasoning_model=reasoning_model,
|
|
4508
|
+
monitoring=self.monitoring,
|
|
4509
|
+
session_state=self.session_state,
|
|
4510
|
+
context=self.context,
|
|
4511
|
+
extra_data=self.extra_data,
|
|
4507
4512
|
)
|
|
4508
4513
|
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
|
|
4509
4514
|
is_groq = is_groq_reasoning_model(reasoning_model)
|
|
@@ -4596,6 +4601,9 @@ class Team:
|
|
|
4596
4601
|
debug_mode=self.debug_mode,
|
|
4597
4602
|
debug_level=self.debug_level,
|
|
4598
4603
|
use_json_mode=use_json_mode,
|
|
4604
|
+
session_state=self.session_state,
|
|
4605
|
+
context=self.context,
|
|
4606
|
+
extra_data=self.extra_data,
|
|
4599
4607
|
)
|
|
4600
4608
|
|
|
4601
4609
|
# Validate reasoning agent
|
|
@@ -4726,7 +4734,11 @@ class Team:
|
|
|
4726
4734
|
from agno.reasoning.openai import is_openai_reasoning_model
|
|
4727
4735
|
|
|
4728
4736
|
reasoning_agent = self.reasoning_agent or get_reasoning_agent(
|
|
4729
|
-
reasoning_model=reasoning_model,
|
|
4737
|
+
reasoning_model=reasoning_model,
|
|
4738
|
+
monitoring=self.monitoring,
|
|
4739
|
+
session_state=self.session_state,
|
|
4740
|
+
context=self.context,
|
|
4741
|
+
extra_data=self.extra_data,
|
|
4730
4742
|
)
|
|
4731
4743
|
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
|
|
4732
4744
|
is_groq = is_groq_reasoning_model(reasoning_model)
|
|
@@ -4817,6 +4829,9 @@ class Team:
|
|
|
4817
4829
|
debug_mode=self.debug_mode,
|
|
4818
4830
|
debug_level=self.debug_level,
|
|
4819
4831
|
use_json_mode=use_json_mode,
|
|
4832
|
+
session_state=self.session_state,
|
|
4833
|
+
context=self.context,
|
|
4834
|
+
extra_data=self.extra_data,
|
|
4820
4835
|
)
|
|
4821
4836
|
|
|
4822
4837
|
# Validate reasoning agent
|
|
@@ -6223,7 +6238,7 @@ class Team:
|
|
|
6223
6238
|
|
|
6224
6239
|
async def arun_member_agents(
|
|
6225
6240
|
task_description: str, expected_output: Optional[str] = None
|
|
6226
|
-
) -> AsyncIterator[str]:
|
|
6241
|
+
) -> AsyncIterator[Union[RunResponseEvent, TeamRunResponseEvent, str]]:
|
|
6227
6242
|
"""
|
|
6228
6243
|
Send the same task to all the member agents and return the responses.
|
|
6229
6244
|
|
|
@@ -6243,92 +6258,177 @@ class Team:
|
|
|
6243
6258
|
session_id, images, videos, audio
|
|
6244
6259
|
)
|
|
6245
6260
|
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
current_agent = member_agent # Create a reference to the current agent
|
|
6251
|
-
current_index = member_agent_index # Create a reference to the current index
|
|
6252
|
-
self._initialize_member(current_agent, session_id=session_id)
|
|
6261
|
+
if stream:
|
|
6262
|
+
# Concurrent streaming: launch each member as a streaming worker and merge events
|
|
6263
|
+
done_marker = object()
|
|
6264
|
+
queue: "asyncio.Queue[Union[RunResponseEvent, TeamRunResponseEvent, str, object]]" = asyncio.Queue()
|
|
6253
6265
|
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6266
|
+
async def stream_member(agent: Union[Agent, "Team"], idx: int) -> None:
|
|
6267
|
+
# Compute expected output per agent (do not mutate shared var)
|
|
6268
|
+
local_expected_output = None if agent.expected_output is not None else expected_output
|
|
6257
6269
|
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6270
|
+
member_agent_task = self._format_member_agent_task(
|
|
6271
|
+
task_description, local_expected_output, team_context_str, team_member_interactions_str
|
|
6272
|
+
)
|
|
6261
6273
|
|
|
6262
|
-
|
|
6263
|
-
|
|
6274
|
+
# Stream events from the member
|
|
6275
|
+
member_stream = await agent.arun(
|
|
6264
6276
|
member_agent_task,
|
|
6265
6277
|
user_id=user_id,
|
|
6266
|
-
# All members have the same session_id
|
|
6267
6278
|
session_id=session_id,
|
|
6268
6279
|
images=images,
|
|
6269
6280
|
videos=videos,
|
|
6270
6281
|
audio=audio,
|
|
6271
6282
|
files=files,
|
|
6272
|
-
stream=
|
|
6283
|
+
stream=True,
|
|
6284
|
+
stream_intermediate_steps=stream_intermediate_steps,
|
|
6273
6285
|
refresh_session_before_write=True,
|
|
6274
6286
|
)
|
|
6275
|
-
check_if_run_cancelled(response)
|
|
6276
6287
|
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6288
|
+
try:
|
|
6289
|
+
async for event in member_stream:
|
|
6290
|
+
check_if_run_cancelled(event)
|
|
6291
|
+
await queue.put(event)
|
|
6292
|
+
finally:
|
|
6293
|
+
# After the stream completes, update memory and team state
|
|
6294
|
+
member_name = agent.name if agent.name else f"agent_{idx}"
|
|
6295
|
+
if isinstance(self.memory, TeamMemory):
|
|
6296
|
+
self.memory = cast(TeamMemory, self.memory)
|
|
6297
|
+
self.memory.add_interaction_to_team_context(
|
|
6298
|
+
member_name=member_name,
|
|
6299
|
+
task=task_description,
|
|
6300
|
+
run_response=agent.run_response, # type: ignore
|
|
6301
|
+
)
|
|
6302
|
+
else:
|
|
6303
|
+
self.memory = cast(Memory, self.memory)
|
|
6304
|
+
self.memory.add_interaction_to_team_context(
|
|
6305
|
+
session_id=session_id,
|
|
6306
|
+
member_name=member_name,
|
|
6307
|
+
task=task_description,
|
|
6308
|
+
run_response=agent.run_response, # type: ignore
|
|
6309
|
+
)
|
|
6310
|
+
|
|
6311
|
+
# Add the member run to the team run response
|
|
6312
|
+
self.run_response = cast(TeamRunResponse, self.run_response)
|
|
6313
|
+
self.run_response.add_member_run(agent.run_response) # type: ignore
|
|
6314
|
+
|
|
6315
|
+
# Update team session/workflow state and media
|
|
6316
|
+
self._update_team_session_state(agent)
|
|
6317
|
+
self._update_workflow_session_state(agent)
|
|
6318
|
+
self._update_team_media(agent.run_response) # type: ignore
|
|
6319
|
+
|
|
6320
|
+
# Signal completion for this member
|
|
6321
|
+
await queue.put(done_marker)
|
|
6322
|
+
|
|
6323
|
+
# Initialize and launch all members
|
|
6324
|
+
tasks: List[asyncio.Task[None]] = []
|
|
6325
|
+
for member_agent_index, member_agent in enumerate(self.members):
|
|
6326
|
+
current_agent = member_agent
|
|
6327
|
+
current_index = member_agent_index
|
|
6328
|
+
self._initialize_member(current_agent, session_id=session_id)
|
|
6329
|
+
tasks.append(asyncio.create_task(stream_member(current_agent, current_index)))
|
|
6330
|
+
|
|
6331
|
+
# Drain queue until all members reported done
|
|
6332
|
+
completed = 0
|
|
6333
|
+
try:
|
|
6334
|
+
while completed < len(tasks):
|
|
6335
|
+
item = await queue.get()
|
|
6336
|
+
if item is done_marker:
|
|
6337
|
+
completed += 1
|
|
6338
|
+
else:
|
|
6339
|
+
yield item # type: ignore
|
|
6340
|
+
finally:
|
|
6341
|
+
# Ensure tasks do not leak on cancellation
|
|
6342
|
+
for t in tasks:
|
|
6343
|
+
if not t.done():
|
|
6344
|
+
t.cancel()
|
|
6345
|
+
# Await cancellation to suppress warnings
|
|
6346
|
+
for t in tasks:
|
|
6347
|
+
with contextlib.suppress(Exception):
|
|
6348
|
+
await t
|
|
6349
|
+
else:
|
|
6350
|
+
# Non-streaming concurrent run of members; collect results when done
|
|
6351
|
+
tasks = []
|
|
6352
|
+
for member_agent_index, member_agent in enumerate(self.members):
|
|
6353
|
+
current_agent = member_agent
|
|
6354
|
+
current_index = member_agent_index
|
|
6355
|
+
self._initialize_member(current_agent, session_id=session_id)
|
|
6356
|
+
|
|
6357
|
+
# Don't override the expected output of a member agent
|
|
6358
|
+
if current_agent.expected_output is not None:
|
|
6359
|
+
expected_output = None
|
|
6360
|
+
|
|
6361
|
+
member_agent_task = self._format_member_agent_task(
|
|
6362
|
+
task_description, expected_output, team_context_str, team_member_interactions_str
|
|
6363
|
+
)
|
|
6364
|
+
|
|
6365
|
+
async def run_member_agent(agent=current_agent, idx=current_index) -> str:
|
|
6366
|
+
response = await agent.arun(
|
|
6367
|
+
member_agent_task,
|
|
6368
|
+
user_id=user_id,
|
|
6369
|
+
# All members have the same session_id
|
|
6287
6370
|
session_id=session_id,
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6371
|
+
images=images,
|
|
6372
|
+
videos=videos,
|
|
6373
|
+
audio=audio,
|
|
6374
|
+
files=files,
|
|
6375
|
+
stream=False,
|
|
6376
|
+
refresh_session_before_write=True,
|
|
6291
6377
|
)
|
|
6378
|
+
check_if_run_cancelled(response)
|
|
6379
|
+
|
|
6380
|
+
member_name = agent.name if agent.name else f"agent_{idx}"
|
|
6381
|
+
self.memory = cast(TeamMemory, self.memory)
|
|
6382
|
+
if isinstance(self.memory, TeamMemory):
|
|
6383
|
+
self.memory = cast(TeamMemory, self.memory)
|
|
6384
|
+
self.memory.add_interaction_to_team_context(
|
|
6385
|
+
member_name=member_name, task=task_description, run_response=agent.run_response
|
|
6386
|
+
)
|
|
6387
|
+
else:
|
|
6388
|
+
self.memory = cast(Memory, self.memory)
|
|
6389
|
+
self.memory.add_interaction_to_team_context(
|
|
6390
|
+
session_id=session_id,
|
|
6391
|
+
member_name=member_name,
|
|
6392
|
+
task=task_description,
|
|
6393
|
+
run_response=agent.run_response,
|
|
6394
|
+
)
|
|
6292
6395
|
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6396
|
+
# Add the member run to the team run response
|
|
6397
|
+
self.run_response = cast(TeamRunResponse, self.run_response)
|
|
6398
|
+
self.run_response.add_member_run(agent.run_response)
|
|
6296
6399
|
|
|
6297
|
-
|
|
6298
|
-
|
|
6400
|
+
# Update team session state
|
|
6401
|
+
self._update_team_session_state(current_agent)
|
|
6299
6402
|
|
|
6300
|
-
|
|
6403
|
+
self._update_workflow_session_state(current_agent)
|
|
6301
6404
|
|
|
6302
|
-
|
|
6303
|
-
|
|
6405
|
+
# Update the team media
|
|
6406
|
+
self._update_team_media(agent.run_response)
|
|
6304
6407
|
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
)
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
else:
|
|
6318
|
-
import json
|
|
6408
|
+
try:
|
|
6409
|
+
if response.content is None and (response.tools is None or len(response.tools) == 0):
|
|
6410
|
+
return f"Agent {member_name}: No response from the member agent."
|
|
6411
|
+
elif isinstance(response.content, str):
|
|
6412
|
+
if len(response.content.strip()) > 0:
|
|
6413
|
+
return f"Agent {member_name}: {response.content}"
|
|
6414
|
+
elif response.tools is not None and len(response.tools) > 0:
|
|
6415
|
+
return f"Agent {member_name}: {','.join([tool.get('content') for tool in response.tools])}"
|
|
6416
|
+
elif issubclass(type(response.content), BaseModel):
|
|
6417
|
+
return f"Agent {member_name}: {response.content.model_dump_json(indent=2)}" # type: ignore
|
|
6418
|
+
else:
|
|
6419
|
+
import json
|
|
6319
6420
|
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6421
|
+
return f"Agent {member_name}: {json.dumps(response.content, indent=2)}"
|
|
6422
|
+
except Exception as e:
|
|
6423
|
+
return f"Agent {member_name}: Error - {str(e)}"
|
|
6323
6424
|
|
|
6324
|
-
|
|
6425
|
+
return f"Agent {member_name}: No Response"
|
|
6325
6426
|
|
|
6326
|
-
|
|
6427
|
+
tasks.append(run_member_agent) # type: ignore
|
|
6327
6428
|
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
yield result
|
|
6429
|
+
results = await asyncio.gather(*[task() for task in tasks]) # type: ignore
|
|
6430
|
+
for result in results:
|
|
6431
|
+
yield result
|
|
6332
6432
|
|
|
6333
6433
|
# Afterward, switch back to the team logger
|
|
6334
6434
|
use_team_logger()
|
agno/tools/bravesearch.py
CHANGED
|
@@ -49,9 +49,9 @@ class BraveSearchTools(Toolkit):
|
|
|
49
49
|
def brave_search(
|
|
50
50
|
self,
|
|
51
51
|
query: str,
|
|
52
|
-
max_results:
|
|
53
|
-
country:
|
|
54
|
-
search_lang:
|
|
52
|
+
max_results: int = 5,
|
|
53
|
+
country: str = "US",
|
|
54
|
+
search_lang: str = "en",
|
|
55
55
|
) -> str:
|
|
56
56
|
"""
|
|
57
57
|
Search Brave for the specified query and return the results.
|
|
@@ -64,8 +64,8 @@ class BraveSearchTools(Toolkit):
|
|
|
64
64
|
Returns:
|
|
65
65
|
str: A JSON formatted string containing the search results.
|
|
66
66
|
"""
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
final_max_results = self.fixed_max_results if self.fixed_max_results is not None else max_results
|
|
68
|
+
final_search_lang = self.fixed_language if self.fixed_language is not None else search_lang
|
|
69
69
|
|
|
70
70
|
if not query:
|
|
71
71
|
return json.dumps({"error": "Please provide a query to search for"})
|
|
@@ -74,9 +74,9 @@ class BraveSearchTools(Toolkit):
|
|
|
74
74
|
|
|
75
75
|
search_params = {
|
|
76
76
|
"q": query,
|
|
77
|
-
"count":
|
|
77
|
+
"count": final_max_results,
|
|
78
78
|
"country": country,
|
|
79
|
-
"search_lang":
|
|
79
|
+
"search_lang": final_search_lang,
|
|
80
80
|
"result_filter": "web",
|
|
81
81
|
}
|
|
82
82
|
|
agno/tools/calculator.py
CHANGED
|
@@ -3,7 +3,7 @@ import math
|
|
|
3
3
|
from typing import Callable, List
|
|
4
4
|
|
|
5
5
|
from agno.tools import Toolkit
|
|
6
|
-
from agno.utils.log import
|
|
6
|
+
from agno.utils.log import log_debug, logger
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class CalculatorTools(Toolkit):
|
|
@@ -53,7 +53,7 @@ class CalculatorTools(Toolkit):
|
|
|
53
53
|
str: JSON string of the result.
|
|
54
54
|
"""
|
|
55
55
|
result = a + b
|
|
56
|
-
|
|
56
|
+
log_debug(f"Adding {a} and {b} to get {result}")
|
|
57
57
|
return json.dumps({"operation": "addition", "result": result})
|
|
58
58
|
|
|
59
59
|
def subtract(self, a: float, b: float) -> str:
|
|
@@ -67,7 +67,7 @@ class CalculatorTools(Toolkit):
|
|
|
67
67
|
str: JSON string of the result.
|
|
68
68
|
"""
|
|
69
69
|
result = a - b
|
|
70
|
-
|
|
70
|
+
log_debug(f"Subtracting {b} from {a} to get {result}")
|
|
71
71
|
return json.dumps({"operation": "subtraction", "result": result})
|
|
72
72
|
|
|
73
73
|
def multiply(self, a: float, b: float) -> str:
|
|
@@ -81,7 +81,7 @@ class CalculatorTools(Toolkit):
|
|
|
81
81
|
str: JSON string of the result.
|
|
82
82
|
"""
|
|
83
83
|
result = a * b
|
|
84
|
-
|
|
84
|
+
log_debug(f"Multiplying {a} and {b} to get {result}")
|
|
85
85
|
return json.dumps({"operation": "multiplication", "result": result})
|
|
86
86
|
|
|
87
87
|
def divide(self, a: float, b: float) -> str:
|
|
@@ -101,7 +101,7 @@ class CalculatorTools(Toolkit):
|
|
|
101
101
|
result = a / b
|
|
102
102
|
except Exception as e:
|
|
103
103
|
return json.dumps({"operation": "division", "error": str(e), "result": "Error"})
|
|
104
|
-
|
|
104
|
+
log_debug(f"Dividing {a} by {b} to get {result}")
|
|
105
105
|
return json.dumps({"operation": "division", "result": result})
|
|
106
106
|
|
|
107
107
|
def exponentiate(self, a: float, b: float) -> str:
|
|
@@ -115,7 +115,7 @@ class CalculatorTools(Toolkit):
|
|
|
115
115
|
str: JSON string of the result.
|
|
116
116
|
"""
|
|
117
117
|
result = math.pow(a, b)
|
|
118
|
-
|
|
118
|
+
log_debug(f"Raising {a} to the power of {b} to get {result}")
|
|
119
119
|
return json.dumps({"operation": "exponentiation", "result": result})
|
|
120
120
|
|
|
121
121
|
def factorial(self, n: int) -> str:
|
|
@@ -131,7 +131,7 @@ class CalculatorTools(Toolkit):
|
|
|
131
131
|
logger.error("Attempt to calculate factorial of a negative number")
|
|
132
132
|
return json.dumps({"operation": "factorial", "error": "Factorial of a negative number is undefined"})
|
|
133
133
|
result = math.factorial(n)
|
|
134
|
-
|
|
134
|
+
log_debug(f"Calculating factorial of {n} to get {result}")
|
|
135
135
|
return json.dumps({"operation": "factorial", "result": result})
|
|
136
136
|
|
|
137
137
|
def is_prime(self, n: int) -> str:
|
|
@@ -164,5 +164,5 @@ class CalculatorTools(Toolkit):
|
|
|
164
164
|
return json.dumps({"operation": "square_root", "error": "Square root of a negative number is undefined"})
|
|
165
165
|
|
|
166
166
|
result = math.sqrt(n)
|
|
167
|
-
|
|
167
|
+
log_debug(f"Calculating square root of {n} to get {result}")
|
|
168
168
|
return json.dumps({"operation": "square_root", "result": result})
|
agno/tools/discord.py
CHANGED
|
@@ -51,12 +51,12 @@ class DiscordTools(Toolkit):
|
|
|
51
51
|
response.raise_for_status()
|
|
52
52
|
return response.json() if response.text else {}
|
|
53
53
|
|
|
54
|
-
def send_message(self, channel_id:
|
|
54
|
+
def send_message(self, channel_id: str, message: str) -> str:
|
|
55
55
|
"""
|
|
56
56
|
Send a message to a Discord channel.
|
|
57
57
|
|
|
58
58
|
Args:
|
|
59
|
-
channel_id (
|
|
59
|
+
channel_id (str): The ID of the channel to send the message to.
|
|
60
60
|
message (str): The text of the message to send.
|
|
61
61
|
|
|
62
62
|
Returns:
|
|
@@ -70,12 +70,12 @@ class DiscordTools(Toolkit):
|
|
|
70
70
|
logger.error(f"Error sending message: {e}")
|
|
71
71
|
return f"Error sending message: {str(e)}"
|
|
72
72
|
|
|
73
|
-
def get_channel_info(self, channel_id:
|
|
73
|
+
def get_channel_info(self, channel_id: str) -> str:
|
|
74
74
|
"""
|
|
75
75
|
Get information about a Discord channel.
|
|
76
76
|
|
|
77
77
|
Args:
|
|
78
|
-
channel_id (
|
|
78
|
+
channel_id (str): The ID of the channel to get information about.
|
|
79
79
|
|
|
80
80
|
Returns:
|
|
81
81
|
str: A JSON string containing the channel information.
|
|
@@ -87,12 +87,12 @@ class DiscordTools(Toolkit):
|
|
|
87
87
|
logger.error(f"Error getting channel info: {e}")
|
|
88
88
|
return f"Error getting channel info: {str(e)}"
|
|
89
89
|
|
|
90
|
-
def list_channels(self, guild_id:
|
|
90
|
+
def list_channels(self, guild_id: str) -> str:
|
|
91
91
|
"""
|
|
92
92
|
List all channels in a Discord server.
|
|
93
93
|
|
|
94
94
|
Args:
|
|
95
|
-
guild_id (
|
|
95
|
+
guild_id (str): The ID of the server to list channels from.
|
|
96
96
|
|
|
97
97
|
Returns:
|
|
98
98
|
str: A JSON string containing the list of channels.
|
|
@@ -104,12 +104,12 @@ class DiscordTools(Toolkit):
|
|
|
104
104
|
logger.error(f"Error listing channels: {e}")
|
|
105
105
|
return f"Error listing channels: {str(e)}"
|
|
106
106
|
|
|
107
|
-
def get_channel_messages(self, channel_id:
|
|
107
|
+
def get_channel_messages(self, channel_id: str, limit: int = 100) -> str:
|
|
108
108
|
"""
|
|
109
109
|
Get the message history of a Discord channel.
|
|
110
110
|
|
|
111
111
|
Args:
|
|
112
|
-
channel_id (
|
|
112
|
+
channel_id (str): The ID of the channel to fetch messages from.
|
|
113
113
|
limit (int): The maximum number of messages to fetch. Defaults to 100.
|
|
114
114
|
|
|
115
115
|
Returns:
|
|
@@ -122,13 +122,13 @@ class DiscordTools(Toolkit):
|
|
|
122
122
|
logger.error(f"Error getting messages: {e}")
|
|
123
123
|
return f"Error getting messages: {str(e)}"
|
|
124
124
|
|
|
125
|
-
def delete_message(self, channel_id:
|
|
125
|
+
def delete_message(self, channel_id: str, message_id: str) -> str:
|
|
126
126
|
"""
|
|
127
127
|
Delete a message from a Discord channel.
|
|
128
128
|
|
|
129
129
|
Args:
|
|
130
|
-
channel_id (
|
|
131
|
-
message_id (
|
|
130
|
+
channel_id (str): The ID of the channel containing the message.
|
|
131
|
+
message_id (str): The ID of the message to delete.
|
|
132
132
|
|
|
133
133
|
Returns:
|
|
134
134
|
str: A success message or error message.
|
agno/tools/duckduckgo.py
CHANGED
|
@@ -5,9 +5,9 @@ from agno.tools import Toolkit
|
|
|
5
5
|
from agno.utils.log import log_debug
|
|
6
6
|
|
|
7
7
|
try:
|
|
8
|
-
from
|
|
8
|
+
from ddgs import DDGS
|
|
9
9
|
except ImportError:
|
|
10
|
-
raise ImportError("`duckduckgo-search` not installed. Please install using `pip install
|
|
10
|
+
raise ImportError("`duckduckgo-search` not installed. Please install using `pip install ddgs`")
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class DuckDuckGoTools(Toolkit):
|
|
@@ -18,9 +18,7 @@ class DuckDuckGoTools(Toolkit):
|
|
|
18
18
|
news (bool): Enable DuckDuckGo news function.
|
|
19
19
|
modifier (Optional[str]): A modifier to be used in the search request.
|
|
20
20
|
fixed_max_results (Optional[int]): A fixed number of maximum results.
|
|
21
|
-
headers (Optional[Any]): Headers to be used in the search request.
|
|
22
21
|
proxy (Optional[str]): Proxy to be used in the search request.
|
|
23
|
-
proxies (Optional[Any]): A list of proxies to be used in the search request.
|
|
24
22
|
timeout (Optional[int]): The maximum number of seconds to wait for a response.
|
|
25
23
|
|
|
26
24
|
"""
|
|
@@ -31,16 +29,12 @@ class DuckDuckGoTools(Toolkit):
|
|
|
31
29
|
news: bool = True,
|
|
32
30
|
modifier: Optional[str] = None,
|
|
33
31
|
fixed_max_results: Optional[int] = None,
|
|
34
|
-
headers: Optional[Any] = None,
|
|
35
32
|
proxy: Optional[str] = None,
|
|
36
|
-
proxies: Optional[Any] = None,
|
|
37
33
|
timeout: Optional[int] = 10,
|
|
38
34
|
verify_ssl: bool = True,
|
|
39
35
|
**kwargs,
|
|
40
36
|
):
|
|
41
|
-
self.headers: Optional[Any] = headers
|
|
42
37
|
self.proxy: Optional[str] = proxy
|
|
43
|
-
self.proxies: Optional[Any] = proxies
|
|
44
38
|
self.timeout: Optional[int] = timeout
|
|
45
39
|
self.fixed_max_results: Optional[int] = fixed_max_results
|
|
46
40
|
self.modifier: Optional[str] = modifier
|
|
@@ -68,11 +62,10 @@ class DuckDuckGoTools(Toolkit):
|
|
|
68
62
|
search_query = f"{self.modifier} {query}" if self.modifier else query
|
|
69
63
|
|
|
70
64
|
log_debug(f"Searching DDG for: {search_query}")
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
65
|
+
with DDGS(proxy=self.proxy, timeout=self.timeout, verify=self.verify_ssl) as ddgs:
|
|
66
|
+
results = ddgs.text(search_query, max_results=actual_max_results)
|
|
74
67
|
|
|
75
|
-
return json.dumps(
|
|
68
|
+
return json.dumps(results, indent=2)
|
|
76
69
|
|
|
77
70
|
def duckduckgo_news(self, query: str, max_results: int = 5) -> str:
|
|
78
71
|
"""Use this function to get the latest news from DuckDuckGo.
|
|
@@ -87,8 +80,7 @@ class DuckDuckGoTools(Toolkit):
|
|
|
87
80
|
actual_max_results = self.fixed_max_results or max_results
|
|
88
81
|
|
|
89
82
|
log_debug(f"Searching DDG news for: {query}")
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
83
|
+
with DDGS(proxy=self.proxy, timeout=self.timeout, verify=self.verify_ssl) as ddgs:
|
|
84
|
+
results = ddgs.news(query, max_results=actual_max_results)
|
|
93
85
|
|
|
94
|
-
return json.dumps(
|
|
86
|
+
return json.dumps(results, indent=2)
|