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(typespec): Add types for computer-use tools #772

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 16 additions & 2 deletions agents-api/agents_api/autogen/Chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@

from .Common import LogitBias
from .Docs import DocReference
from .Tools import ChosenToolCall, NamedToolChoice, Tool
from .Tools import (
ChosenBash20241022,
ChosenComputer20241022,
ChosenFunctionCall,
ChosenTextEditor20241022,
NamedToolChoice,
Tool,
)


class BaseChatOutput(BaseModel):
Expand Down Expand Up @@ -287,7 +294,14 @@ class MessageModel(BaseModel):
Name
"""
tool_calls: Annotated[
list[ChosenToolCall] | None, Field(json_schema_extra={"readOnly": True})
list[
ChosenFunctionCall
| ChosenComputer20241022
| ChosenTextEditor20241022
| ChosenBash20241022
]
| None,
Field(json_schema_extra={"readOnly": True}),
] = []
"""
Tool calls generated by the model.
Expand Down
23 changes: 20 additions & 3 deletions agents-api/agents_api/autogen/Entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel

from .Tools import ChosenToolCall, Tool, ToolResponse
from .Tools import (
ChosenBash20241022,
ChosenComputer20241022,
ChosenFunctionCall,
ChosenTextEditor20241022,
Tool,
ToolResponse,
)


class BaseEntry(BaseModel):
Expand All @@ -31,11 +38,21 @@ class BaseEntry(BaseModel):
content: (
list[Content | ContentModel]
| Tool
| ChosenToolCall
| ChosenFunctionCall
| ChosenComputer20241022
| ChosenTextEditor20241022
| ChosenBash20241022
| str
| ToolResponse
| list[
list[Content | ContentModel] | Tool | ChosenToolCall | str | ToolResponse
list[Content | ContentModel]
| Tool
| ChosenFunctionCall
| ChosenComputer20241022
| ChosenTextEditor20241022
| ChosenBash20241022
| str
| ToolResponse
]
)
source: Literal[
Expand Down
215 changes: 197 additions & 18 deletions agents-api/agents_api/autogen/Tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
from typing import Annotated, Any, Literal
from uuid import UUID

from pydantic import AnyUrl, AwareDatetime, BaseModel, ConfigDict, Field, StrictBool
from pydantic import (
AnyUrl,
AwareDatetime,
BaseModel,
ConfigDict,
Field,
RootModel,
StrictBool,
)


class ApiCallDef(BaseModel):
Expand Down Expand Up @@ -124,6 +132,39 @@ class ApiCallDefUpdate(BaseModel):
"""


class BaseChosenToolCall(BaseModel):
"""
The response tool value generated by the model
"""

model_config = ConfigDict(
populate_by_name=True,
)
type: Literal[
"function",
"integration",
"system",
"api_call",
"computer_20241022",
"text_editor_20241022",
"bash_20241022",
]
"""
Whether this tool is a `function`, `api_call`, `system` etc. (Only `function` tool supported right now)
"""
function: FunctionCallOption | None = None
integration: Any | None = None
system: Any | None = None
api_call: Any | None = None
computer_20241022: ChosenComputer20241022 | None = None
"""
(Alpha) Anthropic new tools
"""
text_editor_20241022: ChosenTextEditor20241022 | None = None
bash_20241022: ChosenBash20241022 | None = None
id: Annotated[UUID | None, Field(json_schema_extra={"readOnly": True})] = None


class BaseIntegrationDef(BaseModel):
"""
Integration definition
Expand Down Expand Up @@ -183,6 +224,18 @@ class BaseIntegrationDefUpdate(BaseModel):
"""


class Bash20241022Def(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["bash_20241022"] = "bash_20241022"
name: str = "bash"


class Bash20241022DefUpdate(Bash20241022Def):
pass


class BraveIntegrationDef(BaseIntegrationDef):
"""
Brave integration definition
Expand Down Expand Up @@ -291,20 +344,121 @@ class BraveSearchSetupUpdate(BaseModel):
"""


class ChosenToolCall(BaseModel):
class ChosenBash20241022(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
command: str | None = None
"""
The response tool value generated by the model
The bash command to run
"""
restart: StrictBool = False
"""
Whether to restart the tool
"""


class ChosenComputer20241022(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function", "integration", "system", "api_call"]
action: Literal[
"key",
"type",
"cursor_position",
"mouse_move",
"left_click",
"right_click",
"middle_click",
"double_click",
"screenshot",
]
"""
Whether this tool is a `function`, `api_call`, `system` etc. (Only `function` tool supported right now)
The action to perform
"""
text: str | None = None
"""
The text to type
"""
coordinate: list[int] | None = None
"""
The (x, y) pixel coordinate to move the cursor to
"""


class ChosenFunctionCall(BaseChosenToolCall):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function"] = "function"
function: FunctionCallOption
"""
The function to call
"""


class ChosenTextEditor20241022(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
command: Literal["str_replace", "insert", "view", "undo_edit"]
"""
The command to run
"""
path: str
"""
The path to the file
"""
file_text: str | None = None
"""
The content of the file to be created
"""
insert_line: int | None = None
"""
The line to insert the new string after
"""
new_str: str | None = None
"""
The new string to insert
"""
old_str: str | None = None
"""
The string in the file to replace
"""
view_range: list[int] | None = None
"""
The line range to view
"""


class Computer20241022Def(BaseModel):
"""
Anthropic new tools
"""

model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["computer_20241022"] = "computer_20241022"
name: str = "computer"
display_width_px: Annotated[int, Field(ge=600)] = 1024
"""
The display width in pixels
"""
display_height_px: Annotated[int, Field(ge=400)] = 768
"""
The display height in pixels
"""
display_number: Annotated[int, Field(ge=1, le=10)] = 1
"""
The display number to use
"""


class Computer20241022DefUpdate(Computer20241022Def):
"""
Anthropic new tools
"""
function: FunctionCallOption | None = None
id: Annotated[UUID, Field(json_schema_extra={"readOnly": True})]


class CreateToolRequest(BaseModel):
Expand Down Expand Up @@ -347,6 +501,12 @@ class CreateToolRequest(BaseModel):
"""
The API call to make
"""
computer_20241022: Computer20241022Def | None = None
"""
(Alpha) Anthropic new tools
"""
text_editor_20241022: TextEditor20241022Def | None = None
bash_20241022: Bash20241022Def | None = None


class DummyIntegrationDef(BaseIntegrationDef):
Expand Down Expand Up @@ -598,6 +758,12 @@ class PatchToolRequest(BaseModel):
"""
The API call to make
"""
computer_20241022: Computer20241022DefUpdate | None = None
"""
(Alpha) Anthropic new tools
"""
text_editor_20241022: TextEditor20241022DefUpdate | None = None
bash_20241022: Bash20241022DefUpdate | None = None


class SpiderFetchArguments(BaseModel):
Expand Down Expand Up @@ -815,6 +981,18 @@ class SystemDefUpdate(BaseModel):
"""


class TextEditor20241022Def(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["text_editor_20241022"] = "text_editor_20241022"
name: str = "str_replace_editor"


class TextEditor20241022DefUpdate(TextEditor20241022Def):
pass


class Tool(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
Expand Down Expand Up @@ -851,6 +1029,12 @@ class Tool(BaseModel):
"""
The API call to make
"""
computer_20241022: Computer20241022Def | None = None
"""
(Alpha) Anthropic new tools
"""
text_editor_20241022: TextEditor20241022Def | None = None
bash_20241022: Bash20241022Def | None = None
created_at: Annotated[AwareDatetime, Field(json_schema_extra={"readOnly": True})]
"""
When this resource was created as UTC date-time
Expand Down Expand Up @@ -913,6 +1097,12 @@ class UpdateToolRequest(BaseModel):
"""
The API call to make
"""
computer_20241022: Computer20241022Def | None = None
"""
(Alpha) Anthropic new tools
"""
text_editor_20241022: TextEditor20241022Def | None = None
bash_20241022: Bash20241022Def | None = None


class WeatherGetArguments(BaseModel):
Expand Down Expand Up @@ -1109,14 +1299,3 @@ class WikipediaSearchArgumentsUpdate(BaseModel):
"""
Maximum number of documents to load
"""


class ChosenFunctionCall(ChosenToolCall):
model_config = ConfigDict(
populate_by_name=True,
)
type: Literal["function"] = "function"
function: FunctionCallOption
"""
The function to call
"""
4 changes: 2 additions & 2 deletions agents-api/agents_api/autogen/openapi_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ def validate_subworkflows(self):
ChatMLContent = (
list[ChatMLTextContentPart | ChatMLImageContentPart]
| Tool
| ChosenToolCall
| BaseChosenToolCall
| str
| ToolResponse
| list[
list[ChatMLTextContentPart | ChatMLImageContentPart]
| Tool
| ChosenToolCall
| BaseChosenToolCall
| str
| ToolResponse
]
Expand Down
Empty file.
4 changes: 3 additions & 1 deletion agents-api/pytype.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ exclude = [

# Space-separated list of files or directories to process.
inputs = [
'.',
'agents_api',
'migrations',
'tests',
]

# Keep going past errors to analyze as many files as possible.
Expand Down
Loading
Loading