@@ -746,221 +746,6 @@ def _convert_message_to_dict(self, message: OpenAIMessage) -> Dict[str, Any]:
746746 """Convert an OpenAIMessage to a Dict[str, Any]."""
747747 return dict (message )
748748
749- async def list_assistants (
750- self : "OpenAIAgent" ,
751- after : Optional [str ] = None ,
752- before : Optional [str ] = None ,
753- limit : Optional [int ] = 20 ,
754- order : Optional [str ] = "desc" ,
755- ) -> Dict [str , Any ]: # noqa: D102
756- """
757- List all assistants using the OpenAI API.
758-
759- Args:
760- after (Optional[str]): Cursor for pagination (fetch after this assistant ID).
761- before (Optional[str]): Cursor for pagination (fetch before this assistant ID).
762- limit (Optional[int]): Number of assistants to return (1-100, default 20).
763- order (Optional[str]): 'asc' or 'desc' by created_at (default 'desc').
764-
765- Returns:
766- Dict[str, Any]: The OpenAI API response containing:
767- - object: 'list'
768- - data: List of assistant objects
769- - first_id: str
770- - last_id: str
771- - has_more: bool
772-
773- Example:
774- .. code-block:: python
775-
776- import asyncio
777- from typing import Dict, Any
778- from autogen_ext.agents.openai import OpenAIAgent
779- from openai import AsyncOpenAI
780- import logging
781-
782-
783- async def example() -> None:
784- client = AsyncOpenAI()
785- agent = OpenAIAgent(
786- name="test_agent",
787- description="Test agent",
788- client=client,
789- model="gpt-4",
790- instructions="You are a helpful assistant.",
791- )
792- assistants: Dict[str, Any] = await agent.list_assistants(limit=5)
793- logging.info(assistants)
794-
795-
796- asyncio.run(example())
797-
798- """
799- params = {"limit" : limit , "order" : order }
800- if after :
801- params ["after" ] = after
802- if before :
803- params ["before" ] = before
804- if hasattr (self ._client , "assistants" ):
805- client_any = cast (Any , self ._client )
806- response = await client_any .assistants .list (** params )
807- if hasattr (response , "model_dump" ):
808- return cast (Dict [str , Any ], response .model_dump ())
809- return cast (Dict [str , Any ], dict (response ))
810- else :
811- raise NotImplementedError ("The OpenAI client does not support listing assistants." )
812-
813- async def retrieve_assistant (self : "OpenAIAgent" , assistant_id : str ) -> Dict [str , Any ]: # noqa: D102
814- """
815- Retrieve a single assistant by its ID using the OpenAI API.
816-
817- Args:
818- assistant_id (str): The ID of the assistant to retrieve.
819-
820- Returns:
821- Dict[str, Any]: The assistant object.
822-
823- Example:
824- .. code-block:: python
825-
826- import asyncio
827- from typing import Dict, Any
828- from autogen_ext.agents.openai import OpenAIAgent
829- from openai import AsyncOpenAI
830- import logging
831-
832-
833- async def example() -> None:
834- client = AsyncOpenAI()
835- agent = OpenAIAgent(
836- name="test_agent",
837- description="Test agent",
838- client=client,
839- model="gpt-4",
840- instructions="You are a helpful assistant.",
841- )
842- assistant: Dict[str, Any] = await agent.retrieve_assistant("asst_abc123")
843- logging.info(assistant)
844-
845-
846- asyncio.run(example())
847-
848- """
849- if hasattr (self ._client , "assistants" ):
850- client_any = cast (Any , self ._client )
851- response = await client_any .assistants .retrieve (assistant_id = assistant_id )
852- if hasattr (response , "model_dump" ):
853- return cast (Dict [str , Any ], response .model_dump ())
854- return cast (Dict [str , Any ], dict (response ))
855- else :
856- raise NotImplementedError ("The OpenAI client does not support retrieving assistants." )
857-
858- async def modify_assistant (
859- self : "OpenAIAgent" ,
860- assistant_id : str ,
861- name : Optional [str ] = None ,
862- description : Optional [str ] = None ,
863- instructions : Optional [str ] = None ,
864- metadata : Optional [Dict [str , Any ]] = None ,
865- model : Optional [str ] = None ,
866- reasoning_effort : Optional [str ] = None ,
867- response_format : Optional [str ] = None ,
868- temperature : Optional [float ] = None ,
869- tool_resources : Optional [Dict [str , Any ]] = None ,
870- tools : Optional [List [Any ]] = None ,
871- top_p : Optional [float ] = None ,
872- ** kwargs : Any ,
873- ) -> Dict [str , Any ]: # noqa: D102
874- """
875- Modify (update) an assistant by its ID using the OpenAI API.
876-
877- Args:
878- assistant_id (str): The ID of the assistant to update.
879- name (Optional[str]): New name for the assistant.
880- description (Optional[str]): New description.
881- instructions (Optional[str]): New instructions.
882- metadata (Optional[dict]): New metadata.
883- model (Optional[str]): New model.
884- reasoning_effort (Optional[str]): New reasoning effort.
885- response_format (Optional[str]): New response format.
886- temperature (Optional[float]): New temperature.
887- tool_resources (Optional[dict]): New tool resources.
888- tools (Optional[list]): New tools.
889- top_p (Optional[float]): New top_p value.
890- **kwargs: Additional keyword arguments.
891-
892- Returns:
893- Dict[str, Any]: The updated assistant object.
894-
895- Example:
896- .. code-block:: python
897-
898- import asyncio
899- from typing import Dict, Any
900- from autogen_ext.agents.openai import OpenAIAgent
901- from openai import AsyncOpenAI
902- import logging
903-
904-
905- async def example() -> None:
906- client = AsyncOpenAI()
907- agent = OpenAIAgent(
908- name="test_agent",
909- description="Test agent",
910- client=client,
911- model="gpt-4",
912- instructions="You are a helpful assistant.",
913- )
914- updated: Dict[str, Any] = await agent.modify_assistant(
915- assistant_id="asst_123",
916- instructions=(
917- "You are an HR bot, and you have access to files to answer employee "
918- "questions about company policies. Always response with info from either "
919- "of the files."
920- ),
921- tools=[{"type": "file_search"}],
922- tool_resources={"file_search": {"vector_store_ids": []}},
923- )
924- logging.info(updated)
925-
926-
927- asyncio.run(example())
928-
929- """
930- params = {k : v for k , v in locals ().items () if k not in {"self" , "assistant_id" , "kwargs" } and v is not None }
931- params .update (kwargs )
932- if hasattr (self ._client , "assistants" ):
933- client_any = cast (Any , self ._client )
934- response = await client_any .assistants .update (assistant_id = assistant_id , ** params )
935- if hasattr (response , "model_dump" ):
936- return cast (Dict [str , Any ], response .model_dump ())
937- return cast (Dict [str , Any ], dict (response ))
938- else :
939- raise NotImplementedError ("The OpenAI client does not support modifying assistants." )
940-
941- async def delete_assistant (self : "OpenAIAgent" , assistant_id : str ) -> Dict [str , Any ]: # noqa: D102
942- """
943- Delete an assistant by its ID using the OpenAI API.
944-
945- Args:
946- assistant_id (str): The ID of the assistant to delete.
947-
948- Returns:
949- Dict[str, Any]: The deletion status object.
950-
951- Example:
952-
953- {"id": "...", "object": "assistant.deleted", "deleted": true}
954- """
955- if hasattr (self ._client , "assistants" ):
956- client_any = cast (Any , self ._client )
957- response = await client_any .assistants .delete (assistant_id = assistant_id )
958- if hasattr (response , "model_dump" ):
959- return cast (Dict [str , Any ], response .model_dump ())
960- return cast (Dict [str , Any ], dict (response ))
961- else :
962- raise NotImplementedError ("The OpenAI client does not support deleting assistants." )
963-
964749 @property
965750 def produced_message_types (
966751 self : "OpenAIAgent" ,
0 commit comments