Skip to content

Commit

Permalink
refactor(agents-api): Refactors
Browse files Browse the repository at this point in the history
Signed-off-by: Diwank Singh Tomer <[email protected]>
  • Loading branch information
creatorrr committed Dec 27, 2024
1 parent 505a25d commit 2f90cb3
Show file tree
Hide file tree
Showing 230 changed files with 2,768 additions and 4,766 deletions.
3 changes: 2 additions & 1 deletion agents-api/agents_api/activities/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

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


async def mock_demo_activity(a: int, b: int) -> int:
Expand Down
16 changes: 8 additions & 8 deletions agents-api/agents_api/activities/excecute_api_call.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import base64
from typing import Any, Optional, TypedDict, Union
from typing import Any, TypedDict

import httpx
from beartype import beartype
Expand All @@ -10,13 +10,13 @@


class RequestArgs(TypedDict):
content: Optional[str]
data: Optional[dict[str, Any]]
json_: Optional[dict[str, Any]]
cookies: Optional[dict[str, str]]
params: Optional[Union[str, dict[str, Any]]]
url: Optional[str]
headers: Optional[dict[str, str]]
content: str | None
data: dict[str, Any] | None
json_: dict[str, Any] | None
cookies: dict[str, str] | None
params: str | dict[str, Any] | None
url: str | None
headers: dict[str, str] | None


@beartype
Expand Down
16 changes: 5 additions & 11 deletions agents-api/agents_api/activities/execute_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async def execute_integration(
setup: dict[str, Any] = {},
) -> Any:
if not isinstance(context.execution_input, ExecutionInput):
raise TypeError("Expected ExecutionInput type for context.execution_input")
msg = "Expected ExecutionInput type for context.execution_input"
raise TypeError(msg)

developer_id = context.execution_input.developer_id
agent_id = context.execution_input.agent.id
Expand All @@ -45,9 +46,7 @@ async def execute_integration(
connection_pool=container.state.postgres_pool,
)

arguments = (
merged_tool_args.get(tool_name, {}) | (integration.arguments or {}) | arguments
)
arguments = merged_tool_args.get(tool_name, {}) | (integration.arguments or {}) | arguments

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

Expand All @@ -62,10 +61,7 @@ async def execute_integration(
arguments=arguments,
)

if (
"error" in integration_service_response
and integration_service_response["error"]
):
if integration_service_response.get("error"):
raise IntegrationExecutionException(
integration=integration,
error=integration_service_response["error"],
Expand All @@ -78,9 +74,7 @@ async def execute_integration(
integration_str = integration.provider + (
"." + integration.method if integration.method else ""
)
activity.logger.error(
f"Error in execute_integration {integration_str}: {e}"
)
activity.logger.error(f"Error in execute_integration {integration_str}: {e}")

raise

Expand Down
12 changes: 6 additions & 6 deletions agents-api/agents_api/activities/execute_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ async def execute_system(
arguments: dict[str, Any] = system.arguments or {}

if not isinstance(context.execution_input, ExecutionInput):
raise TypeError("Expected ExecutionInput type for context.execution_input")
msg = "Expected ExecutionInput type for context.execution_input"
raise TypeError(msg)

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

Expand Down Expand Up @@ -131,9 +132,7 @@ async def execute_system(

# Run the synchronous function in another process
loop = asyncio.get_running_loop()
return await loop.run_in_executor(
process_pool_executor, partial(handler, **arguments)
)
return await loop.run_in_executor(process_pool_executor, partial(handler, **arguments))
except BaseException as e:
if activity.in_activity():
activity.logger.error(f"Error in execute_system_call: {e}")
Expand All @@ -151,19 +150,20 @@ def _create_search_request(arguments: dict) -> Any:
confidence=arguments.pop("confidence", 0.5),
limit=arguments.get("limit", 10),
)
elif "text" in arguments:
if "text" in arguments:
return TextOnlyDocSearchRequest(
text=arguments.pop("text"),
mmr_strength=arguments.pop("mmr_strength", 0),
limit=arguments.get("limit", 10),
)
elif "vector" in arguments:
if "vector" in arguments:
return VectorDocSearchRequest(
vector=arguments.pop("vector"),
mmr_strength=arguments.pop("mmr_strength", 0),
confidence=arguments.pop("confidence", 0.7),
limit=arguments.get("limit", 10),
)
return None


# Keep the existing mock and activity definition
Expand Down
192 changes: 0 additions & 192 deletions agents-api/agents_api/activities/mem_mgmt.py

This file was deleted.

Loading

0 comments on commit 2f90cb3

Please sign in to comment.