You can leverage configuration files to control which components are used and how they behave. For example, you can add extra keys to the configuration to choose between different memory implementations (e.g., basic or semantic memory), enable advanced features like RAG, or adjust other settings dynamically.
Agent Configuration
Enhanced Configuration Example
{
"agent_name": "MathAssistant",
"config": {
"backstory": "I am a helpful assistant with math skills.",
"task": "help users solve mathematical problems using my calculator tool when needed",
"tools": ["calculator"],
"memory": true,
"memory_type": "semantic", // Specify "semantic" to use semantic memory
"rag_enabled": true, // Enable retrieval-augmented generation
"prompt_template": ""
}
}
The configuration file is a JSON file that defines the behavior of your agent. By extending the configuration with additional parameters, you can control which components are used without changing the core code.
How to Use These Config Options
-
Memory Type
In your agent initialization (in
agent.py
), you can check for a key likememory_type
. If it's set to"semantic"
, instantiate theSemanticMemory
class instead of the basicMemory
class. For example:from memory import Memory from semantic_memory import SemanticMemory memory_enabled = self.config.get("config", {}).get("memory", False) memory_type = self.config.get("config", {}).get("memory_type", "basic") if memory_enabled: if memory_type == "semantic": self.memory = SemanticMemory(max_items=10, enabled=True) else: self.memory = Memory(max_items=10, enabled=True) else: self.memory = Memory(max_items=10, enabled=False)
-
RAG Integration
Similarly, if you include a flag like
"rag_enabled": true
in your config, your agent can then conditionally initialize and use the RAG module (rag.py
) during query processing to augment responses.# Example of how to conditionally use RAG in the agent rag_enabled = self.config.get("config", {}).get("rag_enabled", False) if rag_enabled: from rag import RAG self.rag = RAG() else: self.rag = None # Later, during query processing if self.rag: context = self.rag.retrieve_relevant_context(query) # Add context to prompt
-
Tool and Other Settings
You can also include additional keys in your configuration to enable or modify the behavior of tools, streaming responses, evaluation frameworks, etc.
# Example of conditional tool loading based on config tool_list = self.config.get("config", {}).get("tools", []) for tool_name in tool_list: # Load each tool specified in the config
Summary
Using a configuration file in this way allows you to:
- Dynamically switch components: Choose between basic and advanced features without changing the core code.
- Easily experiment: Toggle new features on or off to test different system setups.
- Centralize control: Manage system behavior from a single config file, simplifying deployment and maintenance.
When extending the agent's functionality, try to make new features configurable through the configuration file rather than hardcoding them. This approach makes your agent more flexible and easier to maintain.