1212from typing import Any , Literal
1313
1414from agent_framework import (
15- ChatAgent ,
16- ChatClientProtocol ,
17- ChatMessageStoreProtocol ,
15+ Agent ,
16+ AgentMiddleware ,
17+ ChatMiddleware ,
18+ ChatOptions ,
1819 ContextProvider ,
19- Middleware ,
20+ HistoryProvider ,
21+ SupportsChatGetResponse ,
2022 ToolMode ,
21- ToolProtocol ,
2223)
2324from pydantic import BaseModel
2425
@@ -64,7 +65,7 @@ class AgentBuilder:
6465 )
6566 """
6667
67- def __init__ (self , chat_client : ChatClientProtocol ):
68+ def __init__ (self , chat_client : SupportsChatGetResponse ):
6869 """Initialize the builder with a chat client.
6970
7071 Args:
@@ -75,12 +76,15 @@ def __init__(self, chat_client: ChatClientProtocol):
7576 self ._id : str | None = None
7677 self ._name : str | None = None
7778 self ._description : str | None = None
78- self ._chat_message_store_factory : (
79- Callable [[], ChatMessageStoreProtocol ] | None
80- ) = None
79+ self ._chat_message_store_factory : Callable [[], HistoryProvider ] | None = None
8180 self ._conversation_id : str | None = None
8281 self ._context_providers : ContextProvider | list [ContextProvider ] | None = None
83- self ._middleware : Middleware | list [Middleware ] | None = None
82+ self ._middleware : (
83+ AgentMiddleware
84+ | ChatMiddleware
85+ | list [AgentMiddleware | ChatMiddleware ]
86+ | None
87+ ) = None
8488 self ._frequency_penalty : float | None = None
8589 self ._logit_bias : dict [str | int , float ] | None = None
8690 self ._max_tokens : int | None = None
@@ -96,10 +100,10 @@ def __init__(self, chat_client: ChatClientProtocol):
96100 ToolMode | Literal ["auto" , "required" , "none" ] | dict [str , Any ] | None
97101 ) = "auto"
98102 self ._tools : (
99- ToolProtocol
103+ Any
100104 | Callable [..., Any ]
101105 | MutableMapping [str , Any ]
102- | Sequence [ToolProtocol | Callable [..., Any ] | MutableMapping [str , Any ]]
106+ | Sequence [Any | Callable [..., Any ] | MutableMapping [str , Any ]]
103107 | None
104108 ) = None
105109 self ._top_p : float | None = None
@@ -181,10 +185,10 @@ def with_max_tokens(self, max_tokens: int) -> "AgentBuilder":
181185
182186 def with_tools (
183187 self ,
184- tools : ToolProtocol
188+ tools : Any
185189 | Callable [..., Any ]
186190 | MutableMapping [str , Any ]
187- | Sequence [ToolProtocol | Callable [..., Any ] | MutableMapping [str , Any ]],
191+ | Sequence [Any | Callable [..., Any ] | MutableMapping [str , Any ]],
188192 ) -> "AgentBuilder" :
189193 """Set the tools available to the agent.
190194
@@ -213,7 +217,10 @@ def with_tool_choice(
213217 return self
214218
215219 def with_middleware (
216- self , middleware : Middleware | list [Middleware ]
220+ self ,
221+ middleware : AgentMiddleware
222+ | ChatMiddleware
223+ | list [AgentMiddleware | ChatMiddleware ],
217224 ) -> "AgentBuilder" :
218225 """Set middleware for request/response processing.
219226
@@ -385,7 +392,7 @@ def with_store(self, store: bool) -> "AgentBuilder":
385392 return self
386393
387394 def with_message_store_factory (
388- self , factory : Callable [[], ChatMessageStoreProtocol ]
395+ self , factory : Callable [[], HistoryProvider ]
389396 ) -> "AgentBuilder" :
390397 """Set the message store factory.
391398
@@ -422,7 +429,7 @@ def with_kwargs(self, **kwargs: Any) -> "AgentBuilder":
422429 self ._kwargs .update (kwargs )
423430 return self
424431
425- def build (self ) -> ChatAgent :
432+ def build (self ) -> Agent :
426433 """Build and return the configured ChatAgent.
427434
428435 Returns:
@@ -442,32 +449,52 @@ def build(self) -> ChatAgent:
442449 async with agent:
443450 response = await agent.run("Hello!")
444451 """
445- return ChatAgent (
446- chat_client = self ._chat_client ,
452+ options : dict [str , Any ] = {}
453+ if self ._frequency_penalty is not None :
454+ options ["frequency_penalty" ] = self ._frequency_penalty
455+ if self ._logit_bias is not None :
456+ options ["logit_bias" ] = self ._logit_bias
457+ if self ._max_tokens is not None :
458+ options ["max_tokens" ] = self ._max_tokens
459+ if self ._metadata is not None :
460+ options ["metadata" ] = self ._metadata
461+ if self ._model_id is not None :
462+ options ["model" ] = self ._model_id
463+ if self ._presence_penalty is not None :
464+ options ["presence_penalty" ] = self ._presence_penalty
465+ if self ._response_format is not None :
466+ options ["response_format" ] = self ._response_format
467+ if self ._seed is not None :
468+ options ["seed" ] = self ._seed
469+ if self ._stop is not None :
470+ options ["stop" ] = self ._stop
471+ if self ._store is not None :
472+ options ["store" ] = self ._store
473+ if self ._temperature is not None :
474+ options ["temperature" ] = self ._temperature
475+ if self ._tool_choice is not None :
476+ options ["tool_choice" ] = self ._tool_choice
477+ if self ._top_p is not None :
478+ options ["top_p" ] = self ._top_p
479+ if self ._user is not None :
480+ options ["user" ] = self ._user
481+ if self ._conversation_id is not None :
482+ options ["conversation_id" ] = self ._conversation_id
483+ if self ._additional_chat_options :
484+ options .update (self ._additional_chat_options )
485+
486+ default_options : ChatOptions | None = ChatOptions (** options ) if options else None
487+
488+ return Agent (
489+ client = self ._chat_client ,
447490 instructions = self ._instructions ,
448491 id = self ._id ,
449492 name = self ._name ,
450493 description = self ._description ,
451- chat_message_store_factory = self ._chat_message_store_factory ,
452- conversation_id = self . _conversation_id ,
494+ tools = self ._tools ,
495+ default_options = default_options ,
453496 context_providers = self ._context_providers ,
454497 middleware = self ._middleware ,
455- frequency_penalty = self ._frequency_penalty ,
456- logit_bias = self ._logit_bias ,
457- max_tokens = self ._max_tokens ,
458- metadata = self ._metadata ,
459- model_id = self ._model_id ,
460- presence_penalty = self ._presence_penalty ,
461- response_format = self ._response_format ,
462- seed = self ._seed ,
463- stop = self ._stop ,
464- store = self ._store ,
465- temperature = self ._temperature ,
466- tool_choice = self ._tool_choice ,
467- tools = self ._tools ,
468- top_p = self ._top_p ,
469- user = self ._user ,
470- additional_chat_options = self ._additional_chat_options ,
471498 ** self ._kwargs ,
472499 )
473500
@@ -477,11 +504,12 @@ def create_agent_by_agentinfo(
477504 agent_info : AgentInfo ,
478505 * ,
479506 id : str | None = None ,
480- chat_message_store_factory : Callable [[], ChatMessageStoreProtocol ]
481- | None = None ,
507+ chat_message_store_factory : Callable [[], HistoryProvider ] | None = None ,
482508 conversation_id : str | None = None ,
483509 context_providers : ContextProvider | list [ContextProvider ] | None = None ,
484- middleware : Middleware | list [Middleware ] | None = None ,
510+ middleware : (
511+ AgentMiddleware | ChatMiddleware | list [AgentMiddleware | ChatMiddleware ] | None
512+ ) = None ,
485513 frequency_penalty : float | None = None ,
486514 logit_bias : dict [str | int , float ] | None = None ,
487515 max_tokens : int | None = None ,
@@ -497,16 +525,16 @@ def create_agent_by_agentinfo(
497525 | Literal ["auto" , "required" , "none" ]
498526 | dict [str , Any ]
499527 | None = "auto" ,
500- tools : ToolProtocol
528+ tools : Any
501529 | Callable [..., Any ]
502530 | MutableMapping [str , Any ]
503- | Sequence [ToolProtocol | Callable [..., Any ] | MutableMapping [str , Any ]]
531+ | Sequence [Any | Callable [..., Any ] | MutableMapping [str , Any ]]
504532 | None = None ,
505533 top_p : float | None = None ,
506534 user : str | None = None ,
507535 additional_chat_options : dict [str , Any ] | None = None ,
508536 ** kwargs : Any ,
509- ) -> ChatAgent :
537+ ) -> Agent :
510538 """Create an agent using AgentInfo configuration with full parameter support.
511539
512540 This method creates a chat client from the service configuration and then
@@ -608,17 +636,18 @@ def create_agent_by_agentinfo(
608636
609637 @staticmethod
610638 def create_agent (
611- chat_client : ChatClientProtocol ,
639+ chat_client : SupportsChatGetResponse ,
612640 instructions : str | None = None ,
613641 * ,
614642 id : str | None = None ,
615643 name : str | None = None ,
616644 description : str | None = None ,
617- chat_message_store_factory : Callable [[], ChatMessageStoreProtocol ]
618- | None = None ,
645+ chat_message_store_factory : Callable [[], HistoryProvider ] | None = None ,
619646 conversation_id : str | None = None ,
620647 context_providers : ContextProvider | list [ContextProvider ] | None = None ,
621- middleware : Middleware | list [Middleware ] | None = None ,
648+ middleware : (
649+ AgentMiddleware | ChatMiddleware | list [AgentMiddleware | ChatMiddleware ] | None
650+ ) = None ,
622651 frequency_penalty : float | None = None ,
623652 logit_bias : dict [str | int , float ] | None = None ,
624653 max_tokens : int | None = None ,
@@ -634,16 +663,16 @@ def create_agent(
634663 | Literal ["auto" , "required" , "none" ]
635664 | dict [str , Any ]
636665 | None = "auto" ,
637- tools : ToolProtocol
666+ tools : Any
638667 | Callable [..., Any ]
639668 | MutableMapping [str , Any ]
640- | Sequence [ToolProtocol | Callable [..., Any ] | MutableMapping [str , Any ]]
669+ | Sequence [Any | Callable [..., Any ] | MutableMapping [str , Any ]]
641670 | None = None ,
642671 top_p : float | None = None ,
643672 user : str | None = None ,
644673 additional_chat_options : dict [str , Any ] | None = None ,
645674 ** kwargs : Any ,
646- ) -> ChatAgent :
675+ ) -> Agent :
647676 """Create a Chat Client Agent.
648677
649678 Factory method that creates a ChatAgent instance with the specified configuration.
@@ -745,7 +774,7 @@ def create_agent(
745774 temperature=0.7,
746775 max_tokens=500,
747776 additional_chat_options={
748- "reasoning ": {"effort": " high", "summary": "concise"}
777+ "reasoning_effort ": " high"
749778 }, # OpenAI-specific reasoning options
750779 )
751780
@@ -758,31 +787,51 @@ def create_agent(
758787 ``async with`` to ensure proper initialization and cleanup via the ChatAgent's
759788 async context manager protocol.
760789 """
761- return ChatAgent (
762- chat_client = chat_client ,
790+ options : dict [str , Any ] = {}
791+ if frequency_penalty is not None :
792+ options ["frequency_penalty" ] = frequency_penalty
793+ if logit_bias is not None :
794+ options ["logit_bias" ] = logit_bias
795+ if max_tokens is not None :
796+ options ["max_tokens" ] = max_tokens
797+ if metadata is not None :
798+ options ["metadata" ] = metadata
799+ if model_id is not None :
800+ options ["model" ] = model_id
801+ if presence_penalty is not None :
802+ options ["presence_penalty" ] = presence_penalty
803+ if response_format is not None :
804+ options ["response_format" ] = response_format
805+ if seed is not None :
806+ options ["seed" ] = seed
807+ if stop is not None :
808+ options ["stop" ] = stop
809+ if store is not None :
810+ options ["store" ] = store
811+ if temperature is not None :
812+ options ["temperature" ] = temperature
813+ if tool_choice is not None :
814+ options ["tool_choice" ] = tool_choice
815+ if top_p is not None :
816+ options ["top_p" ] = top_p
817+ if user is not None :
818+ options ["user" ] = user
819+ if conversation_id is not None :
820+ options ["conversation_id" ] = conversation_id
821+ if additional_chat_options :
822+ options .update (additional_chat_options )
823+
824+ default_options : ChatOptions | None = ChatOptions (** options ) if options else None
825+
826+ return Agent (
827+ client = chat_client ,
763828 instructions = instructions ,
764829 id = id ,
765830 name = name ,
766831 description = description ,
767- chat_message_store_factory = chat_message_store_factory ,
768- conversation_id = conversation_id ,
832+ tools = tools ,
833+ default_options = default_options ,
769834 context_providers = context_providers ,
770835 middleware = middleware ,
771- frequency_penalty = frequency_penalty ,
772- logit_bias = logit_bias ,
773- max_tokens = max_tokens ,
774- metadata = metadata ,
775- model_id = model_id ,
776- presence_penalty = presence_penalty ,
777- response_format = response_format ,
778- seed = seed ,
779- stop = stop ,
780- store = store ,
781- temperature = temperature ,
782- tool_choice = tool_choice ,
783- tools = tools ,
784- top_p = top_p ,
785- user = user ,
786- additional_chat_options = additional_chat_options ,
787836 ** kwargs ,
788837 )
0 commit comments