From 5535737756a31ded30767a331d50c75d59db0fc9 Mon Sep 17 00:00:00 2001 From: "filip.chytil" Date: Mon, 8 Jun 2026 19:44:59 +0200 Subject: [PATCH] added string into factory as option --- tinygent/agents/base_agent.py | 25 +++++++++++++++---------- tinygent/core/factory/checkpointer.py | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tinygent/agents/base_agent.py b/tinygent/agents/base_agent.py index 05f4985..236ce26 100644 --- a/tinygent/agents/base_agent.py +++ b/tinygent/agents/base_agent.py @@ -56,15 +56,17 @@ class TinyBaseAgentConfig(AbstractAgentConfig[T], Generic[T]): type: Any = Field(default='base') - middleware: Sequence[AbstractMiddlewareConfig | AbstractMiddleware] = Field( + middleware: Sequence[AbstractMiddlewareConfig | AbstractMiddleware | str] = Field( default_factory=list ) - llm: AbstractLLMConfig | AbstractLLM = Field(...) - tools: Sequence[AbstractToolConfig | AbstractTool] = Field(default_factory=list) - memory: AbstractMemoryConfig | AbstractMemory = Field( + llm: AbstractLLMConfig | AbstractLLM | str = Field(...) + tools: Sequence[AbstractToolConfig | AbstractTool | str] = Field( + default_factory=list + ) + memory: AbstractMemoryConfig | AbstractMemory | str = Field( default_factory=BufferChatMemoryConfig ) - checkpointer: AbstractCheckpointer | AbstractCheckpointerConfig | None = Field( + checkpointer: AbstractCheckpointer | AbstractCheckpointerConfig | str | None = Field( default=None ) @@ -73,7 +75,7 @@ def build(self) -> T: raise NotImplementedError('Subclasses must implement this method.') def build_llm_instance( - self, llm: AbstractLLMConfig | AbstractLLM | None = None + self, llm: AbstractLLMConfig | AbstractLLM | str | None = None ) -> AbstractLLM: """Build LLM instance from config or return existing instance.""" llm = self.llm if llm is None else llm @@ -85,7 +87,7 @@ def build_llm_instance( return build_llm(llm) def build_tools_list( - self, tools: Sequence[AbstractToolConfig | AbstractTool] | None = None + self, tools: Sequence[AbstractToolConfig | AbstractTool | str] | None = None ) -> list[AbstractTool]: """Build list of tool instances from configs or return existing instances.""" tools = self.tools if tools is None else tools @@ -98,7 +100,7 @@ def build_tools_list( ] def build_memory_instance( - self, memory: AbstractMemoryConfig | AbstractMemory | None = None + self, memory: AbstractMemoryConfig | AbstractMemory | str | None = None ) -> AbstractMemory: """Build memory instance from config or return existing instance.""" memory = self.memory if memory is None else memory @@ -111,7 +113,10 @@ def build_memory_instance( def build_checkpointer_instance( self, - checkpointer: AbstractCheckpointer | AbstractCheckpointerConfig | None = None, + checkpointer: AbstractCheckpointer + | AbstractCheckpointerConfig + | str + | None = None, ) -> AbstractCheckpointer: """Build checkpointer instance from config if checkpointer is set.""" checkpointer = self.checkpointer if checkpointer is None else checkpointer @@ -128,7 +133,7 @@ def build_checkpointer_instance( def build_middleware_list( self, - middleware: Sequence[AbstractMiddlewareConfig | AbstractMiddleware] + middleware: Sequence[AbstractMiddlewareConfig | AbstractMiddleware | str] | None = None, ) -> list[AbstractMiddleware]: """Build list of middleware instances from configs or return existing instances.""" diff --git a/tinygent/core/factory/checkpointer.py b/tinygent/core/factory/checkpointer.py index 405330b..e9309c5 100644 --- a/tinygent/core/factory/checkpointer.py +++ b/tinygent/core/factory/checkpointer.py @@ -6,7 +6,8 @@ def build_checkpointer( - checkpointer: dict | AbstractCheckpointer | AbstractCheckpointerConfig, **kwargs + checkpointer: str | dict | AbstractCheckpointer | AbstractCheckpointerConfig, + **kwargs, ) -> AbstractCheckpointer: """Build tiny checkpointer.""" if isinstance(checkpointer, AbstractCheckpointer):