|
15 | 15 | Agent, |
16 | 16 | AgentMiddleware, |
17 | 17 | ChatMiddleware, |
| 18 | + ChatOptions, |
18 | 19 | ContextProvider, |
19 | 20 | HistoryProvider, |
20 | 21 | SupportsChatGetResponse, |
@@ -448,32 +449,53 @@ def build(self) -> Agent: |
448 | 449 | async with agent: |
449 | 450 | response = await agent.run("Hello!") |
450 | 451 | """ |
| 452 | + # Build default_options from model parameters |
| 453 | + options: dict[str, Any] = {} |
| 454 | + if self._frequency_penalty is not None: |
| 455 | + options["frequency_penalty"] = self._frequency_penalty |
| 456 | + if self._logit_bias is not None: |
| 457 | + options["logit_bias"] = self._logit_bias |
| 458 | + if self._max_tokens is not None: |
| 459 | + options["max_tokens"] = self._max_tokens |
| 460 | + if self._metadata is not None: |
| 461 | + options["metadata"] = self._metadata |
| 462 | + if self._model_id is not None: |
| 463 | + options["model"] = self._model_id |
| 464 | + if self._presence_penalty is not None: |
| 465 | + options["presence_penalty"] = self._presence_penalty |
| 466 | + if self._response_format is not None: |
| 467 | + options["response_format"] = self._response_format |
| 468 | + if self._seed is not None: |
| 469 | + options["seed"] = self._seed |
| 470 | + if self._stop is not None: |
| 471 | + options["stop"] = self._stop |
| 472 | + if self._store is not None: |
| 473 | + options["store"] = self._store |
| 474 | + if self._temperature is not None: |
| 475 | + options["temperature"] = self._temperature |
| 476 | + if self._tool_choice is not None: |
| 477 | + options["tool_choice"] = self._tool_choice |
| 478 | + if self._top_p is not None: |
| 479 | + options["top_p"] = self._top_p |
| 480 | + if self._user is not None: |
| 481 | + options["user"] = self._user |
| 482 | + if self._conversation_id is not None: |
| 483 | + options["conversation_id"] = self._conversation_id |
| 484 | + if self._additional_chat_options: |
| 485 | + options.update(self._additional_chat_options) |
| 486 | + |
| 487 | + default_options: ChatOptions | None = ChatOptions(**options) if options else None |
| 488 | + |
451 | 489 | return Agent( |
452 | | - chat_client=self._chat_client, |
| 490 | + client=self._chat_client, |
453 | 491 | instructions=self._instructions, |
454 | 492 | id=self._id, |
455 | 493 | name=self._name, |
456 | 494 | description=self._description, |
457 | | - chat_message_store_factory=self._chat_message_store_factory, |
458 | | - conversation_id=self._conversation_id, |
| 495 | + tools=self._tools, |
| 496 | + default_options=default_options, |
459 | 497 | context_providers=self._context_providers, |
460 | 498 | middleware=self._middleware, |
461 | | - frequency_penalty=self._frequency_penalty, |
462 | | - logit_bias=self._logit_bias, |
463 | | - max_tokens=self._max_tokens, |
464 | | - metadata=self._metadata, |
465 | | - model_id=self._model_id, |
466 | | - presence_penalty=self._presence_penalty, |
467 | | - response_format=self._response_format, |
468 | | - seed=self._seed, |
469 | | - stop=self._stop, |
470 | | - store=self._store, |
471 | | - temperature=self._temperature, |
472 | | - tool_choice=self._tool_choice, |
473 | | - tools=self._tools, |
474 | | - top_p=self._top_p, |
475 | | - user=self._user, |
476 | | - additional_chat_options=self._additional_chat_options, |
477 | 499 | **self._kwargs, |
478 | 500 | ) |
479 | 501 |
|
@@ -766,31 +788,52 @@ def create_agent( |
766 | 788 | ``async with`` to ensure proper initialization and cleanup via the Agent's |
767 | 789 | async context manager protocol. |
768 | 790 | """ |
| 791 | + # Build default_options from model parameters |
| 792 | + options: dict[str, Any] = {} |
| 793 | + if frequency_penalty is not None: |
| 794 | + options["frequency_penalty"] = frequency_penalty |
| 795 | + if logit_bias is not None: |
| 796 | + options["logit_bias"] = logit_bias |
| 797 | + if max_tokens is not None: |
| 798 | + options["max_tokens"] = max_tokens |
| 799 | + if metadata is not None: |
| 800 | + options["metadata"] = metadata |
| 801 | + if model_id is not None: |
| 802 | + options["model"] = model_id |
| 803 | + if presence_penalty is not None: |
| 804 | + options["presence_penalty"] = presence_penalty |
| 805 | + if response_format is not None: |
| 806 | + options["response_format"] = response_format |
| 807 | + if seed is not None: |
| 808 | + options["seed"] = seed |
| 809 | + if stop is not None: |
| 810 | + options["stop"] = stop |
| 811 | + if store is not None: |
| 812 | + options["store"] = store |
| 813 | + if temperature is not None: |
| 814 | + options["temperature"] = temperature |
| 815 | + if tool_choice is not None: |
| 816 | + options["tool_choice"] = tool_choice |
| 817 | + if top_p is not None: |
| 818 | + options["top_p"] = top_p |
| 819 | + if user is not None: |
| 820 | + options["user"] = user |
| 821 | + if conversation_id is not None: |
| 822 | + options["conversation_id"] = conversation_id |
| 823 | + if additional_chat_options: |
| 824 | + options.update(additional_chat_options) |
| 825 | + |
| 826 | + default_options: ChatOptions | None = ChatOptions(**options) if options else None |
| 827 | + |
769 | 828 | return Agent( |
770 | | - chat_client=chat_client, |
| 829 | + client=chat_client, |
771 | 830 | instructions=instructions, |
772 | 831 | id=id, |
773 | 832 | name=name, |
774 | 833 | description=description, |
775 | | - chat_message_store_factory=chat_message_store_factory, |
776 | | - conversation_id=conversation_id, |
| 834 | + tools=tools, |
| 835 | + default_options=default_options, |
777 | 836 | context_providers=context_providers, |
778 | 837 | middleware=middleware, |
779 | | - frequency_penalty=frequency_penalty, |
780 | | - logit_bias=logit_bias, |
781 | | - max_tokens=max_tokens, |
782 | | - metadata=metadata, |
783 | | - model_id=model_id, |
784 | | - presence_penalty=presence_penalty, |
785 | | - response_format=response_format, |
786 | | - seed=seed, |
787 | | - stop=stop, |
788 | | - store=store, |
789 | | - temperature=temperature, |
790 | | - tool_choice=tool_choice, |
791 | | - tools=tools, |
792 | | - top_p=top_p, |
793 | | - user=user, |
794 | | - additional_chat_options=additional_chat_options, |
795 | 838 | **kwargs, |
796 | 839 | ) |
0 commit comments