Skip to content

Commit 2a186ba

Browse files
committed
refactor(agents-api): Refactors
Signed-off-by: Diwank Singh Tomer <[email protected]>
1 parent 505a25d commit 2a186ba

File tree

231 files changed

+2768
-4766
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+2768
-4766
lines changed

Diff for: agents-api/agents_api/activities/demo.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
async def demo_activity(a: int, b: int) -> int:
77
# Should throw an error if testing is not enabled
8-
raise Exception("This should not be called in production")
8+
msg = "This should not be called in production"
9+
raise Exception(msg)
910

1011

1112
async def mock_demo_activity(a: int, b: int) -> int:

Diff for: agents-api/agents_api/activities/excecute_api_call.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import base64
2-
from typing import Any, Optional, TypedDict, Union
2+
from typing import Any, TypedDict
33

44
import httpx
55
from beartype import beartype
@@ -10,13 +10,13 @@
1010

1111

1212
class RequestArgs(TypedDict):
13-
content: Optional[str]
14-
data: Optional[dict[str, Any]]
15-
json_: Optional[dict[str, Any]]
16-
cookies: Optional[dict[str, str]]
17-
params: Optional[Union[str, dict[str, Any]]]
18-
url: Optional[str]
19-
headers: Optional[dict[str, str]]
13+
content: str | None
14+
data: dict[str, Any] | None
15+
json_: dict[str, Any] | None
16+
cookies: dict[str, str] | None
17+
params: str | dict[str, Any] | None
18+
url: str | None
19+
headers: dict[str, str] | None
2020

2121

2222
@beartype

Diff for: agents-api/agents_api/activities/execute_integration.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ async def execute_integration(
2323
setup: dict[str, Any] = {},
2424
) -> Any:
2525
if not isinstance(context.execution_input, ExecutionInput):
26-
raise TypeError("Expected ExecutionInput type for context.execution_input")
26+
msg = "Expected ExecutionInput type for context.execution_input"
27+
raise TypeError(msg)
2728

2829
developer_id = context.execution_input.developer_id
2930
agent_id = context.execution_input.agent.id
@@ -45,9 +46,7 @@ async def execute_integration(
4546
connection_pool=container.state.postgres_pool,
4647
)
4748

48-
arguments = (
49-
merged_tool_args.get(tool_name, {}) | (integration.arguments or {}) | arguments
50-
)
49+
arguments = merged_tool_args.get(tool_name, {}) | (integration.arguments or {}) | arguments
5150

5251
setup = merged_tool_setup.get(tool_name, {}) | (integration.setup or {}) | setup
5352

@@ -62,10 +61,7 @@ async def execute_integration(
6261
arguments=arguments,
6362
)
6463

65-
if (
66-
"error" in integration_service_response
67-
and integration_service_response["error"]
68-
):
64+
if integration_service_response.get("error"):
6965
raise IntegrationExecutionException(
7066
integration=integration,
7167
error=integration_service_response["error"],
@@ -78,9 +74,7 @@ async def execute_integration(
7874
integration_str = integration.provider + (
7975
"." + integration.method if integration.method else ""
8076
)
81-
activity.logger.error(
82-
f"Error in execute_integration {integration_str}: {e}"
83-
)
77+
activity.logger.error(f"Error in execute_integration {integration_str}: {e}")
8478

8579
raise
8680

Diff for: agents-api/agents_api/activities/execute_system.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ async def execute_system(
3939
arguments: dict[str, Any] = system.arguments or {}
4040

4141
if not isinstance(context.execution_input, ExecutionInput):
42-
raise TypeError("Expected ExecutionInput type for context.execution_input")
42+
msg = "Expected ExecutionInput type for context.execution_input"
43+
raise TypeError(msg)
4344

4445
arguments["developer_id"] = context.execution_input.developer_id
4546

@@ -131,9 +132,7 @@ async def execute_system(
131132

132133
# Run the synchronous function in another process
133134
loop = asyncio.get_running_loop()
134-
return await loop.run_in_executor(
135-
process_pool_executor, partial(handler, **arguments)
136-
)
135+
return await loop.run_in_executor(process_pool_executor, partial(handler, **arguments))
137136
except BaseException as e:
138137
if activity.in_activity():
139138
activity.logger.error(f"Error in execute_system_call: {e}")
@@ -151,19 +150,20 @@ def _create_search_request(arguments: dict) -> Any:
151150
confidence=arguments.pop("confidence", 0.5),
152151
limit=arguments.get("limit", 10),
153152
)
154-
elif "text" in arguments:
153+
if "text" in arguments:
155154
return TextOnlyDocSearchRequest(
156155
text=arguments.pop("text"),
157156
mmr_strength=arguments.pop("mmr_strength", 0),
158157
limit=arguments.get("limit", 10),
159158
)
160-
elif "vector" in arguments:
159+
if "vector" in arguments:
161160
return VectorDocSearchRequest(
162161
vector=arguments.pop("vector"),
163162
mmr_strength=arguments.pop("mmr_strength", 0),
164163
confidence=arguments.pop("confidence", 0.7),
165164
limit=arguments.get("limit", 10),
166165
)
166+
return None
167167

168168

169169
# Keep the existing mock and activity definition

Diff for: agents-api/agents_api/activities/mem_mgmt.py

-192
This file was deleted.

0 commit comments

Comments
 (0)