How to Configure Output Formats (List, Dict, Str) in AutoHedge
AutoHedge controls result formatting through the output_type parameter, accepting "list" (default), "dict", or "str" to return conversation history as Python lists, role-grouped dictionaries, or concatenated strings.
The AutoHedge repository by The-Swarm-Corporation enables flexible result serialization for multi-agent trading analysis. When you configure the output format in AutoHedge, you determine how the run() method structures the conversation data returned after completing a hedge allocation task.
Understanding the output_type Parameter
In autohedge/main.py, the AutoHedge class accepts an output_type string during initialization. This value is stored as self.output_type and evaluated inside the run() method to select the appropriate serialization method from the internal Conversation object.
The parameter supports three distinct modes:
"list"– Returns a Python list of message dictionaries (default behavior)"dict"– Returns a dictionary grouping messages by agent role"str"– Returns a single concatenated string of the entire conversation
Available Output Formats
List Format (Default)
When output_type="list", the run() method calls self.conversation.return_messages_as_list() according to the source code in autohedge/main.py. This returns a Python list where each element is a message object containing role and content fields.
from autohedge import AutoHedge
hedge = AutoHedge(output_type="list")
result = hedge.run("Analyze AAPL for 30k allocation")
# Returns: [{'role': 'user', 'content': 'Task: ...'}, {'role': 'director', 'content': '...'}]
Dictionary Format
Setting output_type="dict" triggers Conversation.return_messages_as_dictionary(), which organizes the conversation history into a dictionary keyed by role names such as user, director, or assistant.
from autohedge import AutoHedge
hedge = AutoHedge(output_type="dict")
result = hedge.run("Analyze TSLA for 50k allocation")
# Returns: {'user': [...], 'director': [...], 'assistant': [...]}
String Format
The output_type="str" option invokes Conversation.return_history_as_string(), concatenating all messages into a single textual representation suitable for logging or LLM context windows.
from autohedge import AutoHedge
hedge = AutoHedge(output_type="str")
result = hedge.run("Analyze GOOGL for 10k allocation")
# Returns: "User: Task: ...\nDirector: ...\nAssistant: ..."
Implementation in the Source Code
The output selection logic resides directly in the run() method within autohedge/main.py:
self.output_type = output_type
# ...
if self.output_type == "list":
return self.conversation.return_messages_as_list()
if self.output_type == "dict":
return self.conversation.return_messages_as_dictionary()
if self.output_type == "str":
return self.conversation.return_history_as_string()
The interactive REPL in autohedge/cli.py instantiates AutoHedge() without arguments, defaulting to the list format. Meanwhile, autohedge/workers.py configures individual agent workers (such as risk_agent) with output_type="str" for their internal text generation, though this internal setting remains separate from the main class output configuration.
Dynamic Configuration Changes
While typically set during construction, you can modify the output format dynamically by updating the instance attribute before calling run():
hedge = AutoHedge()
hedge.output_type = "str" # Override default list format
result = hedge.run("Analyze AMZN for 20k allocation")
Summary
- AutoHedge supports three output formats:
list(default),dict, andstr, configured via theoutput_typeconstructor parameter. - Implementation resides in
autohedge/main.py: Therun()method inspectsself.output_typeand delegates to the correspondingConversationmethod. - List format returns raw message objects, dict format groups by role, and str format concatenates into plain text.
- Default CLI behavior in
autohedge/cli.pyuses list output, while internal agents inautohedge/workers.pyuse string outputs for text generation.
Frequently Asked Questions
What is the default output format in AutoHedge?
The default output format is "list", which returns a Python list of message dictionaries containing role and content fields from the conversation history between the user and internal agents.
Can I change the output format after creating an AutoHedge instance?
Yes, you can modify the output_type attribute directly on the instance (e.g., hedge.output_type = "str") before invoking run(). However, setting this via the constructor parameter during instantiation is the recommended approach for code clarity.
How does the dict output format organize conversation data?
The dict format calls return_messages_as_dictionary() to group messages by their role attribute, creating dictionary keys such as user, director, risk_agent, and assistant, where each key maps to a list of that role's messages.
Does the AutoHedge CLI support different output formats?
The built-in REPL in autohedge/cli.py instantiates AutoHedge() without specifying output_type, defaulting to the list format. To obtain dictionary or string output in an interactive session, you must import the class and create a custom instance with your desired output_type parameter.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →