Skip to content

Building AI agents, atomically

added temperature for the llm model

Arunb155d5d9dc33
diff --git a/atomic-agents/atomic_agents/agents/base_agent.py b/atomic-agents/atomic_agents/agents/base_agent.py
index 60bbe6e..260b63e 100644
--- a/atomic-agents/atomic_agents/agents/base_agent.py
+++ b/atomic-agents/atomic_agents/agents/base_agent.py
@@ -37,8 +37,10 @@ class BaseAgentConfig(BaseModel):
)
input_schema: Optional[Type[BaseModel]] = Field(None, description="The schema for the input data.")
output_schema: Optional[Type[BaseModel]] = Field(None, description="The schema for the output data.")
-
model_config = {"arbitrary_types_allowed": True}
+ temperature: Optional[float] = Field(
+ None, description="Temperature for response generation, typically ranging from 0 to 1."
+ )
class BaseAgent:
@@ -76,6 +78,7 @@ class BaseAgent:
self.system_prompt_generator = config.system_prompt_generator or SystemPromptGenerator()
self.initial_memory = self.memory.copy()
self.current_user_input = None
+ self.temperature = 0
def reset_memory(self):
"""
@@ -103,7 +106,9 @@ class BaseAgent:
"content": self.system_prompt_generator.generate_prompt(),
}
] + self.memory.get_history()
- response = self.client.chat.completions.create(model=self.model, messages=messages, response_model=response_model)
+ response = self.client.chat.completions.create(
+ model=self.model, messages=messages, response_model=response_model, temperature=self.temperature
+ )
return response
def run(self, user_input: Optional[Type[BaseIOSchema]] = None) -> Type[BaseIOSchema]:
diff --git a/atomic-agents/tests/agents/test_base_agent.py b/atomic-agents/tests/agents/test_base_agent.py
index ad95edf..a0952a6 100644
--- a/atomic-agents/tests/agents/test_base_agent.py
+++ b/atomic-agents/tests/agents/test_base_agent.py
@@ -58,7 +58,7 @@ def test_initialization(agent, mock_instructor, mock_memory, mock_system_prompt_
assert agent.system_prompt_generator == mock_system_prompt_generator
assert agent.input_schema == BaseAgentInputSchema
assert agent.output_schema == BaseAgentOutputSchema
-
+ assert agent.temperature == 0
def test_reset_memory(agent, mock_memory):
initial_memory = agent.initial_memory