From 9ebf6a4dfb55873823631f4109dc05db7afe8f21 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:27:40 -0500 Subject: [PATCH 1/5] Set temperature to None by default --- src/controlflow/settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controlflow/settings.py b/src/controlflow/settings.py index 387753b..975d04f 100644 --- a/src/controlflow/settings.py +++ b/src/controlflow/settings.py @@ -109,7 +109,9 @@ def _validate_pretty_print_agent_events(cls, data: dict) -> dict: default="openai/gpt-4o", description="The default LLM model for agents.", ) - llm_temperature: float = Field(0.7, description="The temperature for LLM sampling.") + llm_temperature: float | None = Field( + None, description="The temperature for LLM sampling." + ) max_input_tokens: int = Field( 100_000, description="The maximum number of tokens to send to an LLM." ) From e43e62934303a9883df54c7d1f2479453263bfe8 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:29:13 -0500 Subject: [PATCH 2/5] Update settings.py --- src/controlflow/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controlflow/settings.py b/src/controlflow/settings.py index 975d04f..6a00c3e 100644 --- a/src/controlflow/settings.py +++ b/src/controlflow/settings.py @@ -109,7 +109,7 @@ def _validate_pretty_print_agent_events(cls, data: dict) -> dict: default="openai/gpt-4o", description="The default LLM model for agents.", ) - llm_temperature: float | None = Field( + llm_temperature: Union[float, None] = Field( None, description="The temperature for LLM sampling." ) max_input_tokens: int = Field( From 62fc3252efcf73e61b4c50a1753c33aacd197079 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:34:05 -0500 Subject: [PATCH 3/5] Fix 3.9 typing --- src/controlflow/agents/agent.py | 6 +++--- src/controlflow/defaults.py | 4 +--- src/controlflow/orchestration/orchestrator.py | 4 ++-- src/controlflow/orchestration/prompt_templates.py | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/controlflow/agents/agent.py b/src/controlflow/agents/agent.py index 8b691b3..8688828 100644 --- a/src/controlflow/agents/agent.py +++ b/src/controlflow/agents/agent.py @@ -83,7 +83,7 @@ class Agent(ControlFlowModel, abc.ABC): default=False, description="If True, the agent is given tools for interacting with a human user.", ) - memories: list[Memory] | list[AsyncMemory] = Field( + memories: list[Union[Memory, AsyncMemory]] = Field( default=[], description="A list of memory modules for the agent to use.", ) @@ -345,7 +345,7 @@ def _run_model( create_markdown_artifact( markdown=f""" -{response.content or '(No content)'} +{response.content or "(No content)"} #### Payload ```json @@ -409,7 +409,7 @@ async def _run_model_async( create_markdown_artifact( markdown=f""" -{response.content or '(No content)'} +{response.content or "(No content)"} #### Payload ```json diff --git a/src/controlflow/defaults.py b/src/controlflow/defaults.py index b5836e9..0de18f5 100644 --- a/src/controlflow/defaults.py +++ b/src/controlflow/defaults.py @@ -40,9 +40,7 @@ class Defaults(ControlFlowModel): model: Optional[Any] history: History agent: Agent - memory_provider: ( - Optional[Union[MemoryProvider, str]] | Optional[Union[AsyncMemoryProvider, str]] - ) + memory_provider: Optional[Union[MemoryProvider, AsyncMemoryProvider, str]] # add more defaults here def __repr__(self) -> str: diff --git a/src/controlflow/orchestration/orchestrator.py b/src/controlflow/orchestration/orchestrator.py index 03a09de..e949f73 100644 --- a/src/controlflow/orchestration/orchestrator.py +++ b/src/controlflow/orchestration/orchestrator.py @@ -188,7 +188,7 @@ def get_tools(self) -> list[Tool]: tools = as_tools(tools) return tools - def get_memories(self) -> list[Memory] | list[AsyncMemory]: + def get_memories(self) -> list[Union[Memory, AsyncMemory]]: memories = set() memories.update(self.agent.memories) @@ -525,7 +525,7 @@ def compile_prompt(self) -> str: ] prompt = "\n\n".join([p for p in prompts if p]) - logger.debug(f"{'='*10}\nCompiled prompt: {prompt}\n{'='*10}") + logger.debug(f"{'=' * 10}\nCompiled prompt: {prompt}\n{'=' * 10}") return prompt def compile_messages(self) -> list[BaseMessage]: diff --git a/src/controlflow/orchestration/prompt_templates.py b/src/controlflow/orchestration/prompt_templates.py index 4a74df1..9434c6b 100644 --- a/src/controlflow/orchestration/prompt_templates.py +++ b/src/controlflow/orchestration/prompt_templates.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Union from pydantic import model_validator @@ -98,7 +98,7 @@ def should_render(self) -> bool: class MemoryTemplate(Template): template_path: str = "memories.jinja" - memories: list[Memory] | list[AsyncMemory] + memories: list[Union[Memory, AsyncMemory]] def should_render(self) -> bool: return bool(self.memories) From 534c14528c7e9fdd2ef040b7b5cc3c3bd8598249 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:36:03 -0500 Subject: [PATCH 4/5] More 3.9 typing --- src/controlflow/tasks/task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controlflow/tasks/task.py b/src/controlflow/tasks/task.py index b08a548..6683318 100644 --- a/src/controlflow/tasks/task.py +++ b/src/controlflow/tasks/task.py @@ -75,7 +75,7 @@ def __getitem__(self, item): return self.root[item] def __repr__(self) -> str: - return f'Labels: {", ".join(self.root)}' + return f"Labels: {', '.join(self.root)}" class TaskStatus(Enum): @@ -162,7 +162,7 @@ class Task(ControlFlowModel): description="Agents that are allowed to mark this task as complete. If None, all agents are allowed.", ) interactive: bool = False - memories: list[Memory] | list[AsyncMemory] = Field( + memories: list[Union[Memory, AsyncMemory]] = Field( default=[], description="A list of memory modules for the task to use.", ) From 9fe8e1b20ef9514319e284b63e4f2ee76b76bf1a Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:49:53 -0500 Subject: [PATCH 5/5] Finesse temperature passing --- src/controlflow/llm/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/controlflow/llm/models.py b/src/controlflow/llm/models.py index 11a66c8..7b0af5b 100644 --- a/src/controlflow/llm/models.py +++ b/src/controlflow/llm/models.py @@ -52,6 +52,8 @@ def get_model( "To use Google as an LLM provider, please install the `langchain_google_genai` package." ) cls = ChatGoogleGenerativeAI + if temperature is None: + temperature = 0.7 elif provider == "groq": try: from langchain_groq import ChatGroq @@ -60,6 +62,8 @@ def get_model( "To use Groq as an LLM provider, please install the `langchain_groq` package." ) cls = ChatGroq + if temperature is None: + temperature = 0.7 elif provider == "ollama": try: from langchain_ollama import ChatOllama @@ -73,7 +77,9 @@ def get_model( f"Could not load provider `{provider}` automatically. Please provide the LLM class manually." ) - return cls(model=model, temperature=temperature, **kwargs) + if temperature is not None: + kwargs["temperature"] = temperature + return cls(model=model, **kwargs) def _get_initial_default_model() -> BaseChatModel: