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

fix(agents-api): fix create_agent and create_or_update_agent query #503

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ COZO_AUTH_TOKEN=<your_cozo_auth_token>
TEMPORAL_POSTGRES_PASSWORD=<your_temporal_postgres_password>
LITELLM_POSTGRES_PASSWORD=<your_litellm_postgres_password>
LITELLM_MASTER_KEY=<your_litellm_master_key>
LITELLM_SALT_KEY=<your_litellm_salt_key>
LITELLM_REDIS_PASSWORD=<your_litellm_redis_password>
EMBEDDING_SERVICE_BASE=http://text-embeddings-inference-<gpu|cpu> # Use the 'gpu' profile to run on GPU

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def raise_complete_async(context: StepContext, output: StepOutcome) -> Non
# TODO: Create a transtition to "wait" and save the captured_token to the transition

captured_token = activity.info().task_token
captured_token = captured_token.decode('latin-1')
captured_token = captured_token.decode("latin-1")
transition_info = CreateTransitionRequest(
current=context.cursor,
type="wait",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ async def transition_step(

transition_step = activity.defn(name="transition_step")(
transition_step if not testing else mock_transition_step
)
)
26 changes: 25 additions & 1 deletion agents-api/agents_api/models/agent/create_or_update_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ def create_or_update_agent(
}
)

# TODO: remove this
### # Create default agent settings
### # Construct a query to insert default settings for the new agent
### default_settings_query = f"""
### %if {{
### len[count(agent_id)] :=
### *agent_default_settings{{agent_id}},
### agent_id = to_uuid($agent_id)

### ?[should_create] := len[count], count > 0
### }}
### %then {{
### ?[{settings_cols}] <- $settings_vals

### :put agent_default_settings {{
### {settings_cols}
### }}
### }}
### """

# FIXME: This create or update query will overwrite the settings
# Need to find a way to only run the insert query if the agent_default_settings
HamadaSalhab marked this conversation as resolved.
Show resolved Hide resolved

# Create default agent settings
# Construct a query to insert default settings for the new agent
default_settings_query = f"""
Expand All @@ -89,6 +112,7 @@ def create_or_update_agent(
{settings_cols}
}}
"""

# create the agent
# Construct a query to insert the new agent record into the agents table
agent_query = """
Expand Down Expand Up @@ -127,7 +151,7 @@ def create_or_update_agent(

queries = [
verify_developer_id_query(developer_id),
default_settings_query if default_settings else None,
default_settings_query,
agent_query,
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

@rewrap_exceptions(
{
AssertionError: partialclass(HTTPException, status_code=400),
QueryException: partialclass(HTTPException, status_code=400),
ValidationError: partialclass(HTTPException, status_code=400),
TypeError: partialclass(HTTPException, status_code=400),
Expand Down
1 change: 1 addition & 0 deletions agents-api/agents_api/models/session/create_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

@rewrap_exceptions(
{
AssertionError: partialclass(HTTPException, status_code=400),
QueryException: partialclass(HTTPException, status_code=400),
ValidationError: partialclass(HTTPException, status_code=400),
TypeError: partialclass(HTTPException, status_code=400),
Expand Down
27 changes: 27 additions & 0 deletions agents-api/agents_api/models/session/prepare_session_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,33 @@ def prepare_session_data(
"instructions": instructions,
}

# Version where we don't have default settings
agent_data[collect(record)] :=
agents[agent_ids],
agent_id in agent_ids,
*agents{
agent_id,
model,
name,
about,
created_at,
updated_at,
metadata,
instructions,
},
not settings_data[agent_id, _],
record = {
"id": agent_id,
"name": name,
"model": model,
"about": about,
"created_at": created_at,
"updated_at": updated_at,
"metadata": metadata,
"default_settings": {},
"instructions": instructions,
}

user_data[collect(record)] :=
users[user_ids],
user_id in user_ids,
Expand Down
1 change: 1 addition & 0 deletions agents-api/agents_api/routers/agents/create_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async def create_agent(
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
data: CreateAgentRequest,
) -> ResourceCreatedResponse:
# TODO: Validate model name
agent = models.agent.create_agent(
developer_id=x_developer_id,
data=data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async def create_or_update_agent(
data: CreateOrUpdateAgentRequest,
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
) -> ResourceCreatedResponse:
# TODO: Validate model name
agent = models.agent.create_or_update_agent(
developer_id=x_developer_id,
agent_id=agent_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ...autogen.openapi_model import (
CreateOrUpdateSessionRequest,
ResourceCreatedResponse,
ResourceUpdatedResponse,
)
from ...dependencies.developer_id import get_developer_id
from ...models.session.create_or_update_session import (
Expand All @@ -21,14 +21,11 @@ async def create_or_update_session(
x_developer_id: Annotated[UUID4, Depends(get_developer_id)],
session_id: UUID,
data: CreateOrUpdateSessionRequest,
) -> ResourceCreatedResponse:
session = create_session_query(
) -> ResourceUpdatedResponse:
session_updated = create_session_query(
developer_id=x_developer_id,
session_id=session_id,
data=data,
)

return ResourceCreatedResponse(
id=session.id,
created_at=session.created_at,
)
return session_updated
6 changes: 3 additions & 3 deletions agents-api/agents_api/workflows/task_execution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@ async def run(
task_steps.prompt_step,
context,
schedule_to_close_timeout=timedelta(
seconds=30 if debug or testing else 600),
seconds=30 if debug or testing else 600
),
)
state = PartialTransition(
output=new_response.output, type="resume")
state = PartialTransition(output=new_response.output, type="resume")

# case PromptStep(), StepOutcome(
# output=response
Expand Down
Loading