Building AI agents, atomically
update docs, bump version
KennyVaneetvelde2e60f833e0d1
diff --git a/docs/agents/base_agent.html b/docs/agents/base_agent.htmlindex 94b2efd..79fe442 100644--- a/docs/agents/base_agent.html+++ b/docs/agents/base_agent.html@@ -31,6 +31,21 @@ hljs.highlightAll();<section></section><section>+<h2 class="section-title" id="header-functions">Functions</h2>+<dl>+<dt id="atomic_agents.agents.base_agent.model_from_chunks_async_patched"><code class="name flex">+<span>async def <span class="ident">model_from_chunks_async_patched</span></span>(<span>cls, json_chunks, **kwargs)</span>+</code></dt>+<dd>+<div class="desc"></div>+</dd>+<dt id="atomic_agents.agents.base_agent.model_from_chunks_patched"><code class="name flex">+<span>def <span class="ident">model_from_chunks_patched</span></span>(<span>cls, json_chunks, **kwargs)</span>+</code></dt>+<dd>+<div class="desc"></div>+</dd>+</dl></section><section><h2 class="section-title" id="header-classes">Classes</h2>@@ -105,6 +120,7 @@ generating system prompts, and obtaining responses from a language model.</p>self.system_prompt_generator = config.system_prompt_generator or SystemPromptGenerator()self.initial_memory = self.memory.copy()self.current_user_input = None+ self.temperature = config.temperaturedef reset_memory(self):"""@@ -114,7 +130,7 @@ generating system prompts, and obtaining responses from a language model.</p>def get_response(self, response_model=None) -> Type[BaseModel]:"""- Obtains a response from the language model.+ Obtains a response from the language model synchronously.Args:response_model (Type[BaseModel], optional):@@ -132,12 +148,17 @@ generating system prompts, and obtaining responses from a language model.</p>"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 responsedef run(self, user_input: Optional[Type[BaseIOSchema]] = None) -> Type[BaseIOSchema]:"""- Runs the chat agent with the given user input.+ Runs the chat agent with the given user input synchronously.Args:user_input (Optional[Type[BaseIOSchema]]): The input from the user. If not provided, skips adding to memory.@@ -155,6 +176,90 @@ generating system prompts, and obtaining responses from a language model.</p>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,+ )+ 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):+ """+ Runs the chat agent with the given user input, supporting streaming output asynchronously.++ Args:+ user_input (Optional[Type[BaseIOSchema]]): The input from the user. If not provided, skips adding to memory.++ Yields:+ BaseModel: Partial responses from the chat agent.+ """+ if user_input:+ self.memory.initialize_turn()+ self.current_user_input = user_input+ self.memory.add_message("user", user_input)++ messages = [+ {+ "role": "system",+ "content": self.system_prompt_generator.generate_prompt(),+ }+ ] + self.memory.get_history()++ response_stream = self.client.chat.completions.create_partial(+ model=self.model,+ messages=messages,+ response_model=self.output_schema,+ temperature=self.temperature,+ stream=True,+ )++ async for partial_response in response_stream:+ yield partial_response++ full_response_content = self.output_schema(**partial_response.model_dump())+ self.memory.add_message("assistant", full_response_content)+def get_context_provider(self, provider_name: str) -> Type[SystemPromptContextProviderBase]:"""Retrieves a context provider by name.@@ -232,7 +337,21 @@ generating system prompts, and obtaining responses from a language model.</p><span>def <span class="ident">get_response</span></span>(<span>self, response_model=None) ‑> Type[pydantic.main.BaseModel]</span></code></dt><dd>-<div class="desc"><p>Obtains a response from the language model.</p>+<div class="desc"><p>Obtains a response from the language model synchronously.</p>+<h2 id="args">Args</h2>+<p>response_model (Type[BaseModel], optional):+The schema for the response data. If not set, self.output_schema is used.</p>+<h2 id="returns">Returns</h2>+<dl>+<dt><code>Type[BaseModel]</code></dt>+<dd>The response from the language model.</dd>+</dl></div>+</dd>+<dt id="atomic_agents.agents.base_agent.BaseAgent.get_response_async"><code class="name flex">+<span>async def <span class="ident">get_response_async</span></span>(<span>self, response_model=None) ‑> Type[pydantic.main.BaseModel]</span>+</code></dt>+<dd>+<div class="desc"><p>Obtains a response from the language model asynchronously.</p><h2 id="args">Args</h2><p>response_model (Type[BaseModel], optional):The schema for the response data. If not set, self.output_schema is used.</p>@@ -265,7 +384,23 @@ The schema for the response data. If not set, self.output_schema is used.</p><span>def <span class="ident">run</span></span>(<span>self, user_input: Optional[Type[<a title="atomic_agents.lib.base.base_io_schema.BaseIOSchema" href="../lib/base/base_io_schema.html#atomic_agents.lib.base.base_io_schema.BaseIOSchema">BaseIOSchema</a>]] = None) ‑> Type[<a title="atomic_agents.lib.base.base_io_schema.BaseIOSchema" href="../lib/base/base_io_schema.html#atomic_agents.lib.base.base_io_schema.BaseIOSchema">BaseIOSchema</a>]</span></code></dt><dd>-<div class="desc"><p>Runs the chat agent with the given user input.</p>+<div class="desc"><p>Runs the chat agent with the given user input synchronously.</p>+<h2 id="args">Args</h2>+<dl>+<dt><strong><code>user_input</code></strong> : <code>Optional[Type[BaseIOSchema]]</code></dt>+<dd>The input from the user. If not provided, skips adding to memory.</dd>+</dl>+<h2 id="returns">Returns</h2>+<dl>+<dt><code>Type[BaseIOSchema]</code></dt>+<dd>The response from the chat agent.</dd>+</dl></div>+</dd>+<dt id="atomic_agents.agents.base_agent.BaseAgent.run_async"><code class="name flex">+<span>async def <span class="ident">run_async</span></span>(<span>self, user_input: Optional[Type[<a title="atomic_agents.lib.base.base_io_schema.BaseIOSchema" href="../lib/base/base_io_schema.html#atomic_agents.lib.base.base_io_schema.BaseIOSchema">BaseIOSchema</a>]] = None) ‑> Type[<a title="atomic_agents.lib.base.base_io_schema.BaseIOSchema" href="../lib/base/base_io_schema.html#atomic_agents.lib.base.base_io_schema.BaseIOSchema">BaseIOSchema</a>]</span>+</code></dt>+<dd>+<div class="desc"><p>Runs the chat agent with the given user input asynchronously.</p><h2 id="args">Args</h2><dl><dt><strong><code>user_input</code></strong> : <code>Optional[Type[BaseIOSchema]]</code></dt>@@ -277,6 +412,22 @@ The schema for the response data. If not set, self.output_schema is used.</p><dd>The response from the chat agent.</dd></dl></div></dd>+<dt id="atomic_agents.agents.base_agent.BaseAgent.stream_response_async"><code class="name flex">+<span>async def <span class="ident">stream_response_async</span></span>(<span>self, user_input: Optional[Type[<a title="atomic_agents.lib.base.base_io_schema.BaseIOSchema" href="../lib/base/base_io_schema.html#atomic_agents.lib.base.base_io_schema.BaseIOSchema">BaseIOSchema</a>]] = None)</span>+</code></dt>+<dd>+<div class="desc"><p>Runs the chat agent with the given user input, supporting streaming output asynchronously.</p>+<h2 id="args">Args</h2>+<dl>+<dt><strong><code>user_input</code></strong> : <code>Optional[Type[BaseIOSchema]]</code></dt>+<dd>The input from the user. If not provided, skips adding to memory.</dd>+</dl>+<h2 id="yields">Yields</h2>+<dl>+<dt><code>BaseModel</code></dt>+<dd>Partial responses from the chat agent.</dd>+</dl></div>+</dd><dt id="atomic_agents.agents.base_agent.BaseAgent.unregister_context_provider"><code class="name flex"><span>def <span class="ident">unregister_context_provider</span></span>(<span>self, provider_name: str)</span></code></dt>@@ -352,8 +503,11 @@ validated to form a valid model.</p>)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}</code></pre>+ model_config = {"arbitrary_types_allowed": True}+ temperature: Optional[float] = Field(+ 0,+ description="Temperature for response generation, typically ranging from 0 to 1.",+ )</code></pre></details><h3>Ancestors</h3><ul class="hlist">@@ -397,6 +551,10 @@ validated to form a valid model.</p><dd><div class="desc"><p>The type of the None singleton.</p></div></dd>+<dt id="atomic_agents.agents.base_agent.BaseAgentConfig.temperature"><code class="name">var <span class="ident">temperature</span> : Optional[float]</code></dt>+<dd>+<div class="desc"><p>The type of the None singleton.</p></div>+</dd></dl></dd><dt id="atomic_agents.agents.base_agent.BaseAgentInputSchema"><code class="flex name class">@@ -507,6 +665,12 @@ validated to form a valid model.</p><li><code><a title="atomic_agents.agents" href="index.html">atomic_agents.agents</a></code></li></ul></li>+<li><h3><a href="#header-functions">Functions</a></h3>+<ul class="">+<li><code><a title="atomic_agents.agents.base_agent.model_from_chunks_async_patched" href="#atomic_agents.agents.base_agent.model_from_chunks_async_patched">model_from_chunks_async_patched</a></code></li>+<li><code><a title="atomic_agents.agents.base_agent.model_from_chunks_patched" href="#atomic_agents.agents.base_agent.model_from_chunks_patched">model_from_chunks_patched</a></code></li>+</ul>+</li><li><h3><a href="#header-classes">Classes</a></h3><ul><li>@@ -514,11 +678,14 @@ validated to form a valid model.</p><ul class=""><li><code><a title="atomic_agents.agents.base_agent.BaseAgent.get_context_provider" href="#atomic_agents.agents.base_agent.BaseAgent.get_context_provider">get_context_provider</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgent.get_response" href="#atomic_agents.agents.base_agent.BaseAgent.get_response">get_response</a></code></li>+<li><code><a title="atomic_agents.agents.base_agent.BaseAgent.get_response_async" href="#atomic_agents.agents.base_agent.BaseAgent.get_response_async">get_response_async</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgent.input_schema" href="#atomic_agents.agents.base_agent.BaseAgent.input_schema">input_schema</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgent.output_schema" href="#atomic_agents.agents.base_agent.BaseAgent.output_schema">output_schema</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgent.register_context_provider" href="#atomic_agents.agents.base_agent.BaseAgent.register_context_provider">register_context_provider</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgent.reset_memory" href="#atomic_agents.agents.base_agent.BaseAgent.reset_memory">reset_memory</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgent.run" href="#atomic_agents.agents.base_agent.BaseAgent.run">run</a></code></li>+<li><code><a title="atomic_agents.agents.base_agent.BaseAgent.run_async" href="#atomic_agents.agents.base_agent.BaseAgent.run_async">run_async</a></code></li>+<li><code><a title="atomic_agents.agents.base_agent.BaseAgent.stream_response_async" href="#atomic_agents.agents.base_agent.BaseAgent.stream_response_async">stream_response_async</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgent.unregister_context_provider" href="#atomic_agents.agents.base_agent.BaseAgent.unregister_context_provider">unregister_context_provider</a></code></li></ul></li>@@ -534,6 +701,7 @@ validated to form a valid model.</p><li><code><a title="atomic_agents.agents.base_agent.BaseAgentConfig.model_fields" href="#atomic_agents.agents.base_agent.BaseAgentConfig.model_fields">model_fields</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgentConfig.output_schema" href="#atomic_agents.agents.base_agent.BaseAgentConfig.output_schema">output_schema</a></code></li><li><code><a title="atomic_agents.agents.base_agent.BaseAgentConfig.system_prompt_generator" href="#atomic_agents.agents.base_agent.BaseAgentConfig.system_prompt_generator">system_prompt_generator</a></code></li>+<li><code><a title="atomic_agents.agents.base_agent.BaseAgentConfig.temperature" href="#atomic_agents.agents.base_agent.BaseAgentConfig.temperature">temperature</a></code></li></ul></li><li>diff --git a/docs/lib/base/base_io_schema.html b/docs/lib/base/base_io_schema.htmlindex 2750a58..e99920c 100644--- a/docs/lib/base/base_io_schema.html+++ b/docs/lib/base/base_io_schema.html@@ -69,7 +69,7 @@ validated to form a valid model.</p>description = cls.__doc__if not description or not description.strip():- if cls.__module__ != "instructor.function_calls":+ if cls.__module__ != "instructor.function_calls" and not hasattr(cls, "from_streaming_response"):raise ValueError(f"{cls.__name__} must have a non-empty docstring to serve as its description")@classmethoddiff --git a/docs/lib/components/agent_memory.html b/docs/lib/components/agent_memory.htmlindex 1cc2b24..c46e1de 100644--- a/docs/lib/components/agent_memory.html+++ b/docs/lib/components/agent_memory.html@@ -46,7 +46,7 @@ hljs.highlightAll();<dt><strong><code>history</code></strong> : <code>List[<a title="atomic_agents.lib.components.agent_memory.Message" href="#atomic_agents.lib.components.agent_memory.Message">Message</a>]</code></dt><dd>A list of messages representing the chat history.</dd><dt><strong><code>max_messages</code></strong> : <code>Optional[int]</code></dt>-<dd>Maximum number of turns to keep in history.</dd>+<dd>Maximum number of messages to keep in history.</dd><dt><strong><code>current_turn_id</code></strong> : <code>Optional[str]</code></dt><dd>The ID of the current turn.</dd></dl>@@ -54,7 +54,8 @@ hljs.highlightAll();<h2 id="args">Args</h2><dl><dt><strong><code>max_messages</code></strong> : <code>Optional[int]</code></dt>-<dd>Maximum number of turns to keep in history.</dd>+<dd>Maximum number of messages to keep in history.+When exceeded, oldest messages are removed first.</dd></dl></div><details class="source"><summary>@@ -66,7 +67,7 @@ hljs.highlightAll();Attributes:history (List[Message]): A list of messages representing the chat history.- max_messages (Optional[int]): Maximum number of turns to keep in history.+ max_messages (Optional[int]): Maximum number of messages to keep in history.current_turn_id (Optional[str]): The ID of the current turn."""@@ -75,7 +76,8 @@ hljs.highlightAll();Initializes the AgentMemory with an empty history and optional constraints.Args:- max_messages (Optional[int]): Maximum number of turns to keep in history.+ max_messages (Optional[int]): Maximum number of messages to keep in history.+ When exceeded, oldest messages are removed first."""self.history: List[Message] = []self.max_messages = max_messages@@ -150,6 +152,32 @@ hljs.highlightAll();"""return self.current_turn_id+ def delete_turn_id(self, turn_id: int):+ """+ Delete messages from the memory by its turn ID.++ Args:+ turn_id (int): The turn ID of the message to delete.++ Returns:+ str: A success message with the deleted turn ID.++ Raises:+ ValueError: If the specified turn ID is not found in the memory.+ """+ initial_length = len(self.history)+ self.history = [msg for msg in self.history if msg.turn_id != turn_id]++ if len(self.history) == initial_length:+ raise ValueError(f"Turn ID {turn_id} not found in memory.")++ # Update current_turn_id if necessary+ if not len(self.history):+ self.current_turn_id = None+ elif turn_id == self.current_turn_id:+ # Always update to the last message's turn_id+ self.current_turn_id = self.history[-1].turn_id+def get_message_count(self) -> int:"""Returns the number of messages in the chat history.@@ -256,6 +284,27 @@ hljs.highlightAll();<dd>A copy of the chat memory.</dd></dl></div></dd>+<dt id="atomic_agents.lib.components.agent_memory.AgentMemory.delete_turn_id"><code class="name flex">+<span>def <span class="ident">delete_turn_id</span></span>(<span>self, turn_id: int)</span>+</code></dt>+<dd>+<div class="desc"><p>Delete messages from the memory by its turn ID.</p>+<h2 id="args">Args</h2>+<dl>+<dt><strong><code>turn_id</code></strong> : <code>int</code></dt>+<dd>The turn ID of the message to delete.</dd>+</dl>+<h2 id="returns">Returns</h2>+<dl>+<dt><code>str</code></dt>+<dd>A success message with the deleted turn ID.</dd>+</dl>+<h2 id="raises">Raises</h2>+<dl>+<dt><code>ValueError</code></dt>+<dd>If the specified turn ID is not found in the memory.</dd>+</dl></div>+</dd><dt id="atomic_agents.lib.components.agent_memory.AgentMemory.dump"><code class="name flex"><span>def <span class="ident">dump</span></span>(<span>self) ‑> str</span></code></dt>@@ -413,6 +462,7 @@ validated to form a valid model.</p><ul class="two-column"><li><code><a title="atomic_agents.lib.components.agent_memory.AgentMemory.add_message" href="#atomic_agents.lib.components.agent_memory.AgentMemory.add_message">add_message</a></code></li><li><code><a title="atomic_agents.lib.components.agent_memory.AgentMemory.copy" href="#atomic_agents.lib.components.agent_memory.AgentMemory.copy">copy</a></code></li>+<li><code><a title="atomic_agents.lib.components.agent_memory.AgentMemory.delete_turn_id" href="#atomic_agents.lib.components.agent_memory.AgentMemory.delete_turn_id">delete_turn_id</a></code></li><li><code><a title="atomic_agents.lib.components.agent_memory.AgentMemory.dump" href="#atomic_agents.lib.components.agent_memory.AgentMemory.dump">dump</a></code></li><li><code><a title="atomic_agents.lib.components.agent_memory.AgentMemory.get_current_turn_id" href="#atomic_agents.lib.components.agent_memory.AgentMemory.get_current_turn_id">get_current_turn_id</a></code></li><li><code><a title="atomic_agents.lib.components.agent_memory.AgentMemory.get_history" href="#atomic_agents.lib.components.agent_memory.AgentMemory.get_history">get_history</a></code></li>diff --git a/pyproject.toml b/pyproject.tomlindex 6573c49..b8b3587 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"[tool.poetry]name = "atomic-agents"-version = "1.0.8"+version = "1.0.9"description = "A versatile framework for creating and managing intelligent agents."authors = ["Kenny Vaneetvelde <[email protected]>"]readme = "README.md"