Skip to content

Commit

Permalink
Merge branch 'dev' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorrr authored Oct 4, 2024
2 parents 15f68e4 + a6bcbbe commit 22117d9
Show file tree
Hide file tree
Showing 74 changed files with 450 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,17 @@ jobs:
restore-keys: |
${{ runner.os }}-agents-api-poetry-
- name: Cache pytype
uses: actions/cache@v4
with:
path: agents-api/.pytype
key: ${{ runner.os }}-agents-api-pytype-${{ hashFiles('agents-api/**/*.py') }}
restore-keys: |
${{ runner.os }}-agents-api-pytype-
- name: Install dependencies
run: |
cd agents-api
poetry install
- name: Typecheck
run: |
cd agents-api
poetry run poe typecheck
- name: Lint and format
run: |
cd agents-api
poetry run poe format
poetry run poe lint
- name: Run tests
run: |
cd agents-api
poetry run poe test
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "refactor: Lint agents-api (CI)"
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/test-agents-api-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Test agents-api
run-name: ${{ github.actor }} is testing the code

# TODO: Fix CI github actions
# SCRUM-26

on: [pull_request]

jobs:
Test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install and configure Poetry
uses: snok/install-poetry@v1

- name: Configure Poetry to use .venv
run: |
cd agents-api
poetry config virtualenvs.in-project true
- name: Cache Poetry virtualenv
uses: actions/cache@v4
with:
path: agents-api/.venv
key: ${{ runner.os }}-agents-api-poetry-${{ hashFiles('agents-api/poetry.lock') }}
restore-keys: |
${{ runner.os }}-agents-api-poetry-
- name: Install dependencies
run: |
cd agents-api
poetry install
- name: Run tests
run: |
cd agents-api
poetry run poe test --fail-limit 1
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
56 changes: 56 additions & 0 deletions .github/workflows/typecheck-agents-api-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Typecheck agents-api
run-name: ${{ github.actor }} is typechecking the code

# TODO: Fix CI github actions
# SCRUM-26

on: [pull_request]

jobs:
Typecheck:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install and configure Poetry
uses: snok/install-poetry@v1

- name: Configure Poetry to use .venv
run: |
cd agents-api
poetry config virtualenvs.in-project true
- name: Cache Poetry virtualenv
uses: actions/cache@v4
with:
path: agents-api/.venv
key: ${{ runner.os }}-agents-api-poetry-${{ hashFiles('agents-api/poetry.lock') }}
restore-keys: |
${{ runner.os }}-agents-api-poetry-
- name: Cache pytype
uses: actions/cache@v4
with:
path: agents-api/.pytype
key: ${{ runner.os }}-agents-api-pytype-${{ github.base_ref }}
restore-keys: |
${{ runner.os }}-agents-api-pytype-
- name: Install dependencies
run: |
cd agents-api
poetry install
- name: Typecheck
run: |
cd agents-api
poetry run poe typecheck
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
2 changes: 1 addition & 1 deletion agents-api/agents_api/activities/truncation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from beartype import beartype
from temporalio import activity

from agents_api.autogen.openapi_model import Entry
from ..autogen.openapi_model import Entry

# from agents_api.models.entry.entries_summarization import get_toplevel_entries_query

Expand Down
31 changes: 0 additions & 31 deletions agents-api/agents_api/autogen/Tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class CreateToolRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function", "integration", "system", "api_call"] = "function"
"""
Whether this tool is a `function`, `api_call`, `system` etc. (Only `function` tool supported right now)
"""
name: Annotated[str, Field(max_length=40, pattern="^[^\\W0-9]\\w*$")]
"""
Name of the tool (must be unique for this agent and a valid python identifier string )
Expand Down Expand Up @@ -168,10 +164,6 @@ class NamedToolChoice(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function", "integration", "system", "api_call"]
"""
Whether this tool is a `function`, `api_call`, `system` etc. (Only `function` tool supported right now)
"""
function: FunctionCallOption | None = None


Expand All @@ -183,10 +175,6 @@ class PatchToolRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function", "integration", "system", "api_call"] = "function"
"""
Whether this tool is a `function`, `api_call`, `system` etc. (Only `function` tool supported right now)
"""
name: Annotated[str | None, Field(None, max_length=40, pattern="^[^\\W0-9]\\w*$")]
"""
Name of the tool (must be unique for this agent and a valid python identifier string )
Expand Down Expand Up @@ -247,10 +235,6 @@ class Tool(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function", "integration", "system", "api_call"] = "function"
"""
Whether this tool is a `function`, `api_call`, `system` etc. (Only `function` tool supported right now)
"""
name: Annotated[str, Field(max_length=40, pattern="^[^\\W0-9]\\w*$")]
"""
Name of the tool (must be unique for this agent and a valid python identifier string )
Expand Down Expand Up @@ -291,10 +275,6 @@ class UpdateToolRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function", "integration", "system", "api_call"] = "function"
"""
Whether this tool is a `function`, `api_call`, `system` etc. (Only `function` tool supported right now)
"""
name: Annotated[str, Field(max_length=40, pattern="^[^\\W0-9]\\w*$")]
"""
Name of the tool (must be unique for this agent and a valid python identifier string )
Expand All @@ -316,14 +296,3 @@ class ChosenFunctionCall(ChosenToolCall):
"""
The function to call
"""


class NamedFunctionChoice(NamedToolChoice):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function"] = "function"
function: FunctionCallOption
"""
The function to call
"""
97 changes: 22 additions & 75 deletions agents-api/agents_api/autogen/openapi_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,88 +77,35 @@ class InputChatMLMessage(Message):
pass


# Custom types (not generated correctly)
# --------------------------------------

ChatMLContent = (
list[ChatMLTextContentPart | ChatMLImageContentPart]
| Tool
| ChosenToolCall
| str
| ToolResponse
| list[
list[ChatMLTextContentPart | ChatMLImageContentPart]
| Tool
| ChosenToolCall
| str
| ToolResponse
]
)

# Extract ChatMLRole
ChatMLRole = BaseEntry.model_fields["role"].annotation

# Extract ChatMLSource
ChatMLSource = BaseEntry.model_fields["source"].annotation

# Extract ExecutionStatus
ExecutionStatus = Execution.model_fields["status"].annotation

# Extract TransitionType
TransitionType = Transition.model_fields["type"].annotation

# Assertions to ensure consistency (optional, but recommended for runtime checks)
assert ChatMLRole == BaseEntry.model_fields["role"].annotation
assert ChatMLSource == BaseEntry.model_fields["source"].annotation
assert ExecutionStatus == Execution.model_fields["status"].annotation
assert TransitionType == Transition.model_fields["type"].annotation


# Create models
# -------------
# Patches
# -------


class CreateTransitionRequest(Transition):
# The following fields are optional in this
def type_property(self: BaseModel) -> str:
return (
"function"
if self.function
else "integration"
if self.integration
else "system"
if self.system
else "api_call"
if self.api_call
else None
)

id: UUID | None = None
execution_id: UUID | None = None
created_at: AwareDatetime | None = None
updated_at: AwareDatetime | None = None
metadata: dict[str, Any] | None = None
task_token: str | None = None

# Patch original Tool class to add 'type' property
TaskTool.type = computed_field(property(type_property))

class CreateEntryRequest(BaseEntry):
timestamp: Annotated[
float, Field(ge=0.0, default_factory=lambda: utcnow().timestamp())
]
# Patch original Tool class to add 'type' property
Tool.type = computed_field(property(type_property))

@classmethod
def from_model_input(
cls: Type[Self],
model: str,
*,
role: ChatMLRole,
content: ChatMLContent,
name: str | None = None,
source: ChatMLSource,
**kwargs: dict,
) -> Self:
tokenizer: dict = select_tokenizer(model=model)
token_count = token_counter(
model=model, messages=[{"role": role, "content": content, "name": name}]
)
# Patch original UpdateToolRequest class to add 'type' property
UpdateToolRequest.type = computed_field(property(type_property))

return cls(
role=role,
content=content,
name=name,
source=source,
tokenizer=tokenizer["type"],
token_count=token_count,
**kwargs,
)
# Patch original PatchToolRequest class to add 'type' property
PatchToolRequest.type = computed_field(property(type_property))


# Patch Task Workflow Steps
Expand Down
3 changes: 1 addition & 2 deletions agents-api/agents_api/clients/worker/worker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import httpx

from agents_api.env import temporal_worker_url

from ...env import temporal_worker_url
from .types import (
MemoryManagementTask,
MemoryManagementTaskArgs,
Expand Down
6 changes: 4 additions & 2 deletions agents-api/agents_api/common/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""
This module defines a structured hierarchy of custom exceptions for the agents API, aimed at handling specific error scenarios encountered across various operations. These exceptions are designed to provide clear, actionable error messages and appropriate HTTP status codes, enhancing the API's robustness and usability.
This module defines a structured hierarchy of custom exceptions for the agents API, aimed at handling specific error scenarios encountered across various operations.
These exceptions are designed to provide clear, actionable error messages and appropriate HTTP status codes, enhancing the API's robustness and usability.
Exceptions are organized into categories based on the domain of operation, including:
- Agent-related operations (agents.py): Exceptions such as `AgentNotFoundError` and `AgentToolNotFoundError` cater to errors specific to agent management.
- Session management (sessions.py): Defines exceptions like `SessionNotFoundError` for handling errors related to session operations.
- User interactions (users.py): Includes exceptions such as `UserNotFoundError` for addressing issues encountered during user-related operations.
All custom exceptions extend from `BaseCommonException`, which encapsulates common attributes and behavior, including the error message and HTTP status code. This structured approach to exception handling facilitates precise and meaningful error feedback to API consumers, thereby improving the overall developer experience.
All custom exceptions extend from `BaseCommonException`, which encapsulates common attributes and behavior, including the error message and HTTP status code.
This structured approach to exception handling facilitates precise and meaningful error feedback to API consumers, thereby improving the overall developer experience.
"""


Expand Down
Loading

0 comments on commit 22117d9

Please sign in to comment.