Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agents-api): Remove auto_blob_store in favor of interceptor based system #977

Draft
wants to merge 33 commits into
base: f/switch-to-pg
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3a627b1
feat(agents-api): Add entry queries
Vedantsahai18 Dec 16, 2024
6aa4807
refactor: Lint agents-api (CI)
Vedantsahai18 Dec 16, 2024
a8d2068
chore: update the entyr queries
Vedantsahai18 Dec 17, 2024
dc2002f
refactor: Lint agents-api (CI)
Vedantsahai18 Dec 17, 2024
70b7598
chore: inner join developer table with entry queries
Vedantsahai18 Dec 17, 2024
5cf8767
refactor: Lint agents-api (CI)
Vedantsahai18 Dec 17, 2024
c85c2fe
Merge branch 'f/switch-to-pg' into f/add-entry-queries
Vedantsahai18 Dec 17, 2024
8b6b0d9
wip(agents-api): Add session sql queries
creatorrr Dec 17, 2024
065c7d2
refactor: Lint agents-api (CI)
creatorrr Dec 17, 2024
2eb10d3
chore: developers and user refactor + add test for entry queries + bu…
Vedantsahai18 Dec 18, 2024
b064234
refactor: Lint agents-api (CI)
Vedantsahai18 Dec 18, 2024
a728129
feat(agents-api): Fix tests for sessions
creatorrr Dec 18, 2024
372f320
refactor: Lint agents-api (CI)
creatorrr Dec 18, 2024
c9d3139
Merge branch 'f/session-queries' into f/add-entry-queries
creatorrr Dec 18, 2024
2b907ef
wip(agents-api): Entry queries
creatorrr Dec 18, 2024
2b8686c
refactor: Lint agents-api (CI)
creatorrr Dec 18, 2024
94aa3ce
fix(agents-api): change modelname to model in BaseEntry
Ahmad-mtos Dec 18, 2024
a5d4301
Merge pull request #966 from julep-ai/f/add-entry-queries
Ahmad-mtos Dec 18, 2024
64a34cd
feat(agents-api): add agent queries tests
Ahmad-mtos Dec 17, 2024
8cc2ae3
feat(agents-api): implement agent queries and tests
Ahmad-mtos Dec 18, 2024
e745acc
refactor: Lint agents-api (CI)
Ahmad-mtos Dec 18, 2024
2f392f7
fix(agents-api): misc fixes
Ahmad-mtos Dec 18, 2024
0579f3c
refactor: Lint agents-api (CI)
Ahmad-mtos Dec 18, 2024
46a3b39
Merge branch 'f/switch-to-pg' into f/session-queries
creatorrr Dec 18, 2024
1b7a022
wip
Ahmad-mtos Dec 18, 2024
db31801
refactor: Lint agents-api (CI)
Ahmad-mtos Dec 18, 2024
638fefb
chore: minor refactors
Vedantsahai18 Dec 18, 2024
2ba91ad
refactor: Lint agents-api (CI)
Vedantsahai18 Dec 18, 2024
57e453f
feat(memory-store,agents-api): Move is_leaf handling to postgres
creatorrr Dec 19, 2024
bbdbb4b
fix(agents-api): fix sessions and agents queries / tests
Ahmad-mtos Dec 19, 2024
8361e7d
refactor: Lint agents-api (CI)
Ahmad-mtos Dec 19, 2024
e158f3a
feat(agents-api): Remove auto_blob_store in favor of interceptor base…
creatorrr Dec 19, 2024
ca5f4e2
fix(agents-api): Minor fixes
creatorrr Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/embed_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
from temporalio import activity

from ..clients import cozo, litellm
from ..common.storage_handler import auto_blob_store
from ..env import testing
from ..models.docs.embed_snippets import embed_snippets as embed_snippets_query
from .types import EmbedDocsPayload


@auto_blob_store(deep=True)
@beartype
async def embed_docs(
payload: EmbedDocsPayload, cozo_client=None, max_batch_size: int = 100
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/excecute_api_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from temporalio import activity

from ..autogen.openapi_model import ApiCallDef
from ..common.storage_handler import auto_blob_store
from ..env import testing


Expand All @@ -20,7 +19,6 @@ class RequestArgs(TypedDict):
headers: Optional[dict[str, str]]


@auto_blob_store(deep=True)
@beartype
async def execute_api_call(
api_call: ApiCallDef,
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/execute_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
from ..clients import integrations
from ..common.exceptions.tools import IntegrationExecutionException
from ..common.protocol.tasks import ExecutionInput, StepContext
from ..common.storage_handler import auto_blob_store
from ..env import testing
from ..models.tools import get_tool_args_from_metadata


@auto_blob_store(deep=True)
@beartype
async def execute_integration(
context: StepContext,
Expand Down
7 changes: 1 addition & 6 deletions agents-api/agents_api/activities/execute_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
VectorDocSearchRequest,
)
from ..common.protocol.tasks import ExecutionInput, StepContext
from ..common.storage_handler import auto_blob_store, load_from_blob_store_if_remote
from ..env import testing
from ..queries.developer import get_developer
from ..queries.developers import get_developer
from .utils import get_handler

# For running synchronous code in the background
process_pool_executor = ProcessPoolExecutor()


@auto_blob_store(deep=True)
@beartype
async def execute_system(
context: StepContext,
Expand All @@ -37,9 +35,6 @@ async def execute_system(
"""Execute a system call with the appropriate handler and transformed arguments."""
arguments: dict[str, Any] = system.arguments or {}

if set(arguments.keys()) == {"bucket", "key"}:
arguments = await load_from_blob_store_if_remote(arguments)

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

Expand Down
12 changes: 4 additions & 8 deletions agents-api/agents_api/activities/sync_items_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@

@beartype
async def save_inputs_remote_fn(inputs: list[Any]) -> list[Any | RemoteObject]:
from ..common.storage_handler import store_in_blob_store_if_large
from ..common.interceptors import offload_if_large

return await asyncio.gather(
*[store_in_blob_store_if_large(input) for input in inputs]
)
return await asyncio.gather(*[offload_if_large(input) for input in inputs])


@beartype
async def load_inputs_remote_fn(inputs: list[Any | RemoteObject]) -> list[Any]:
from ..common.storage_handler import load_from_blob_store_if_remote
from ..common.interceptors import load_if_remote

return await asyncio.gather(
*[load_from_blob_store_if_remote(input) for input in inputs]
)
return await asyncio.gather(*[load_if_remote(input) for input in inputs])


save_inputs_remote = activity.defn(name="save_inputs_remote")(save_inputs_remote_fn)
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/base_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from temporalio import activity # noqa: E402
from thefuzz import fuzz # noqa: E402

from ...common.storage_handler import auto_blob_store # noqa: E402
from ...env import testing # noqa: E402
from ..utils import get_evaluator # noqa: E402

Expand Down Expand Up @@ -63,7 +62,6 @@ def _recursive_evaluate(expr, evaluator: SimpleEval):
raise ValueError(f"Invalid expression: {expr}")


@auto_blob_store(deep=True)
@beartype
async def base_evaluate(
exprs: Any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
from temporalio import activity

from ... import models
from ...common.storage_handler import auto_blob_store
from ...env import testing


@auto_blob_store(deep=True)
@beartype
async def cozo_query_step(
query_name: str,
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/evaluate_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

from ...activities.utils import simple_eval_dict
from ...common.protocol.tasks import StepContext, StepOutcome
from ...common.storage_handler import auto_blob_store
from ...env import testing


@auto_blob_store(deep=True)
@beartype
async def evaluate_step(
context: StepContext,
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/for_each_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
StepContext,
StepOutcome,
)
from ...common.storage_handler import auto_blob_store
from ...env import testing
from .base_evaluate import base_evaluate


@auto_blob_store(deep=True)
@beartype
async def for_each_step(context: StepContext) -> StepOutcome:
try:
Expand Down
5 changes: 2 additions & 3 deletions agents-api/agents_api/activities/task_steps/get_value_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from temporalio import activity

from ...common.protocol.tasks import StepContext, StepOutcome
from ...common.storage_handler import auto_blob_store
from ...env import testing


# TODO: We should use this step to query the parent workflow and get the value from the workflow context
# SCRUM-1
@auto_blob_store(deep=True)


@beartype
async def get_value_step(
context: StepContext,
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/if_else_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
StepContext,
StepOutcome,
)
from ...common.storage_handler import auto_blob_store
from ...env import testing
from .base_evaluate import base_evaluate


@auto_blob_store(deep=True)
@beartype
async def if_else_step(context: StepContext) -> StepOutcome:
# NOTE: This activity is only for logging, so we just evaluate the expression
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/log_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
StepContext,
StepOutcome,
)
from ...common.storage_handler import auto_blob_store
from ...common.utils.template import render_template
from ...env import testing


@auto_blob_store(deep=True)
@beartype
async def log_step(context: StepContext) -> StepOutcome:
# NOTE: This activity is only for logging, so we just evaluate the expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
StepContext,
StepOutcome,
)
from ...common.storage_handler import auto_blob_store
from ...env import testing
from .base_evaluate import base_evaluate


@auto_blob_store(deep=True)
@beartype
async def map_reduce_step(context: StepContext) -> StepOutcome:
try:
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/prompt_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
litellm, # We dont directly import `acompletion` so we can mock it
)
from ...common.protocol.tasks import ExecutionInput, StepContext, StepOutcome
from ...common.storage_handler import auto_blob_store
from ...common.utils.template import render_template
from ...env import debug
from .base_evaluate import base_evaluate
Expand Down Expand Up @@ -62,7 +61,6 @@ def format_tool(tool: Tool) -> dict:


@activity.defn
@auto_blob_store(deep=True)
@beartype
async def prompt_step(context: StepContext) -> StepOutcome:
# Get context data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

from ...autogen.openapi_model import CreateTransitionRequest
from ...common.protocol.tasks import StepContext
from ...common.storage_handler import auto_blob_store
from .transition_step import original_transition_step


@activity.defn
@auto_blob_store(deep=True)
@beartype
async def raise_complete_async(context: StepContext, output: Any) -> None:
activity_info = activity.info()
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/return_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
StepContext,
StepOutcome,
)
from ...common.storage_handler import auto_blob_store
from ...env import testing
from .base_evaluate import base_evaluate


@auto_blob_store(deep=True)
@beartype
async def return_step(context: StepContext) -> StepOutcome:
try:
Expand Down
5 changes: 2 additions & 3 deletions agents-api/agents_api/activities/task_steps/set_value_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

from ...activities.utils import simple_eval_dict
from ...common.protocol.tasks import StepContext, StepOutcome
from ...common.storage_handler import auto_blob_store
from ...env import testing


# TODO: We should use this step to signal to the parent workflow and set the value on the workflow context
# SCRUM-2
@auto_blob_store(deep=True)


@beartype
async def set_value_step(
context: StepContext,
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/switch_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
StepContext,
StepOutcome,
)
from ...common.storage_handler import auto_blob_store
from ...env import testing
from ..utils import get_evaluator


@auto_blob_store(deep=True)
@beartype
async def switch_step(context: StepContext) -> StepOutcome:
try:
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/tool_call_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
StepContext,
StepOutcome,
)
from ...common.storage_handler import auto_blob_store


# FIXME: This shouldn't be here.
Expand Down Expand Up @@ -47,7 +46,6 @@ def construct_tool_call(


@activity.defn
@auto_blob_store(deep=True)
@beartype
async def tool_call_step(context: StepContext) -> StepOutcome:
assert isinstance(context.current_step, ToolCallStep)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from ...autogen.openapi_model import CreateTransitionRequest, Transition
from ...clients.temporal import get_workflow_handle
from ...common.protocol.tasks import ExecutionInput, StepContext
from ...common.storage_handler import load_from_blob_store_if_remote
from ...env import (
temporal_activity_after_retry_timeout,
testing,
Expand Down Expand Up @@ -48,11 +47,6 @@ async def transition_step(
TaskExecutionWorkflow.set_last_error, LastErrorInput(last_error=None)
)

# Load output from blob store if it is a remote object
transition_info.output = await load_from_blob_store_if_remote(
transition_info.output
)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

from ...autogen.openapi_model import WaitForInputStep
from ...common.protocol.tasks import StepContext, StepOutcome
from ...common.storage_handler import auto_blob_store
from ...env import testing
from .base_evaluate import base_evaluate


@auto_blob_store(deep=True)
@beartype
async def wait_for_input_step(context: StepContext) -> StepOutcome:
try:
Expand Down
2 changes: 0 additions & 2 deletions agents-api/agents_api/activities/task_steps/yield_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

from ...autogen.openapi_model import TransitionTarget, YieldStep
from ...common.protocol.tasks import ExecutionInput, StepContext, StepOutcome
from ...common.storage_handler import auto_blob_store
from ...env import testing
from .base_evaluate import base_evaluate


@auto_blob_store(deep=True)
@beartype
async def yield_step(context: StepContext) -> StepOutcome:
try:
Expand Down
10 changes: 6 additions & 4 deletions agents-api/agents_api/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
from contextlib import asynccontextmanager

import asyncpg
from fastapi import FastAPI
from prometheus_fastapi_instrumentator import Instrumentator

Expand All @@ -11,9 +9,13 @@

@asynccontextmanager
async def lifespan(app: FastAPI):
app.state.postgres_pool = await create_db_pool()
if not app.state.postgres_pool:
app.state.postgres_pool = await create_db_pool()

yield
await app.state.postgres_pool.close()

if app.state.postgres_pool:
await app.state.postgres_pool.close()


app: FastAPI = FastAPI(
Expand Down
1 change: 1 addition & 0 deletions agents-api/agents_api/autogen/Entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BaseEntry(BaseModel):
]
tokenizer: str
token_count: int
model: str = "gpt-4o-mini"
tool_calls: (
list[
ChosenFunctionCall
Expand Down
Loading
Loading