Skip to content

Building AI agents, atomically

Merge branch 'main' into feature/streamline_async

Kenny Vaneetvelde3a30d29f61c8
diff --cc atomic-agents/atomic_agents/agents/base_agent.py
index 18769df,a2d756f..4e14ef1
--- a/atomic-agents/atomic_agents/agents/base_agent.py
+++ b/atomic-agents/atomic_agents/agents/base_agent.py
@@@ -165,7 -176,56 +174,8 @@@ class BaseAgent
return response
- async def get_response_async(self, response_model=None) -> Type[BaseModel]:
- """
- Obtains a response from the language model asynchronously.
-
- Args:
- response_model (Type[BaseModel], optional):
- The schema for the response data. If not set, self.output_schema is used.
-
- Returns:
- Type[BaseModel]: The response from the language model.
- """
- if response_model is None:
- response_model = self.output_schema
-
- messages = [
- {
- "role": "system",
- "content": self.system_prompt_generator.generate_prompt(),
- }
- ] + self.memory.get_history()
- response = await self.client.chat.completions.create(
- model=self.model,
- messages=messages,
- response_model=response_model,
- temperature=self.temperature,
- max_tokens=self.max_tokens,
- )
- return response
+
- async def run_async(self, user_input: Optional[Type[BaseIOSchema]] = None) -> Type[BaseIOSchema]:
- """
- Runs the chat agent with the given user input asynchronously.
-
- Args:
- user_input (Optional[Type[BaseIOSchema]]): The input from the user. If not provided, skips adding to memory.
-
- Returns:
- Type[BaseIOSchema]: The response from the chat agent.
- """
- if user_input:
- self.memory.initialize_turn()
- self.current_user_input = user_input
- self.memory.add_message("user", user_input)
-
- response = await self.get_response_async(response_model=self.output_schema)
- self.memory.add_message("assistant", response)
-
- return response
-
- async def stream_response_async(self, user_input: Optional[Type[BaseIOSchema]] = None):
+ async def run_async(self, user_input: Optional[Type[BaseIOSchema]] = None):
"""
Runs the chat agent with the given user input, supporting streaming output asynchronously.