Python: added create_agent and removed need for Field in annotations (#380)

* added create_agent

* add minimal sample

* allow multiple annotations

* improved docstring
This commit is contained in:
Eduard van Valkenburg
2025-08-08 19:55:20 +02:00
committed by GitHub
Unverified
parent 757c48e367
commit 8f27e63df6
5 changed files with 86 additions and 16 deletions
@@ -4,7 +4,7 @@ import asyncio
from abc import ABC, abstractmethod
from collections.abc import AsyncIterable, Awaitable, Callable, MutableMapping, MutableSequence, Sequence
from functools import wraps
from typing import Any, Generic, Literal, Protocol, TypeVar, runtime_checkable
from typing import TYPE_CHECKING, Any, Generic, Literal, Protocol, TypeVar, runtime_checkable
from pydantic import BaseModel
@@ -23,6 +23,9 @@ from ._types import (
GeneratedEmbeddings,
)
if TYPE_CHECKING:
from ._agents import ChatClientAgent
TInput = TypeVar("TInput", contravariant=True)
TEmbedding = TypeVar("TEmbedding")
TChatClientBase = TypeVar("TChatClientBase", bound="ChatClientBase")
@@ -641,6 +644,36 @@ class ChatClientBase(AFBaseModel, ABC):
"""
return None
def create_agent(
self,
*,
name: str,
instructions: str,
tools: AITool
| list[AITool]
| Callable[..., Any]
| list[Callable[..., Any]]
| MutableMapping[str, Any]
| list[MutableMapping[str, Any]]
| None = None,
**kwargs: Any,
) -> "ChatClientAgent":
"""Create an agent with the given name and instructions.
Args:
name: The name of the agent.
instructions: The instructions for the agent.
tools: Optional list of tools to associate with the agent.
**kwargs: Additional keyword arguments to pass to the agent.
See ChatClientAgent for all the available options.
Returns:
An instance of ChatClientAgent.
"""
from ._agents import ChatClientAgent
return ChatClientAgent(chat_client=self, name=name, instructions=instructions, tools=tools, **kwargs)
# region: Embedding Client