| 1 | from openai.types.chat import ChatCompletionMessage |
| 2 | from openai.types.chat.chat_completion_message_tool_call import ( |
| 3 | ChatCompletionMessageToolCall, |
| 4 | Function, |
| 5 | ) |
| 6 | from typing import List, Callable, Union, Optional |
| 7 | |
| 8 | # Third-party imports |
| 9 | from pydantic import BaseModel |
| 10 | |
| 11 | AgentFunction = Callable[[], Union[str, "Agent", dict]] |
| 12 | |
| 13 | |
| 14 | class Agent(BaseModel): |
| 15 | name: str = "Agent" |
| 16 | model: str = "gpt-4o" |
| 17 | instructions: Union[str, Callable[[], str]] = "You are a helpful agent." |
| 18 | functions: List[AgentFunction] = [] |
| 19 | tool_choice: str = None |
| 20 | parallel_tool_calls: bool = True |
| 21 | |
| 22 | |
| 23 | class Response(BaseModel): |
| 24 | messages: List = [] |
| 25 | agent: Optional[Agent] = None |
| 26 | context_variables: dict = {} |
| 27 | |
| 28 | |
| 29 | class Result(BaseModel): |
| 30 | """ |
| 31 | Encapsulates the possible return values for an agent function. |
| 32 | |
| 33 | Attributes: |
| 34 | value (str): The result value as a string. |
| 35 | agent (Agent): The agent instance, if applicable. |
| 36 | context_variables (dict): A dictionary of context variables. |
| 37 | """ |
| 38 | |
| 39 | value: str = "" |
| 40 | agent: Optional[Agent] = None |
| 41 | context_variables: dict = {} |