AutoHedge Class Output Formats: List, Dict, and String Explained
The AutoHedge class supports three output formats—list, dictionary, and string—controlled via the output_type parameter during initialization.
The AutoHedge class serves as the central orchestrator for automated trading cycles in The-Swarm-Corporation/AutoHedge repository. When initializing an instance, developers can specify how conversation results should be returned using the output_type parameter. This flexibility allows seamless integration with different downstream processing pipelines, whether you need structured data for programmatic analysis or plain text for logging.
Supported AutoHedge Output Formats
The AutoHedge class, defined in autohedge/main.py, accepts three distinct values for the output_type argument. Each format corresponds to a specific method on the internal conversation object, transforming the same underlying data into different representations.
List Format (Default)
When output_type="list" (the default setting), the run method returns self.conversation.return_messages_as_list().
This produces a Python list where each element is a message dictionary containing keys such as role, content, and timestamp. This format preserves the chronological order of the conversation and is ideal for iterating through message sequences or storing structured logs in databases.
Dictionary Format
Setting output_type="dict" returns self.conversation.return_messages_as_dictionary().
This format yields a dictionary keyed by role, making it efficient to retrieve the latest message from a specific participant (such as the director agent or worker agents) without scanning the entire history. Use this when you need quick lookups of specific role outputs rather than the full conversation flow.
String Format
With output_type="str", the method returns self.conversation.return_history_as_string().
This generates a single concatenated string containing the entire conversation history. This format is optimal for human-readable logging, debugging output, or feeding conversation context into text-based processing tools.
Output Format Implementation Details
The output format selection logic resides in the run method of autohedge/main.py (lines 52-60). After the director agent completes processing, the code checks self.output_type and routes to the appropriate conversation method.
If an unsupported value is supplied for output_type, the implementation gracefully falls back to the list format, ensuring the system remains functional even with invalid configuration. The initialization logic accepting this parameter appears in lines 15-23 of the same file.
Working with AutoHedge Output Formats
Here are practical examples demonstrating each format:
from autohedge.main import AutoHedge
# 1. List output (default)
auto_list = AutoHedge(output_type="list")
logs_list = auto_list.run("Analyze AAPL")
print("List output:", logs_list)
# 2. Dictionary output
auto_dict = AutoHedge(output_type="dict")
logs_dict = auto_dict.run("Analyze GOOGL")
print("Dict output:", logs_dict)
# 3. String output
auto_str = AutoHedge(output_type="str")
logs_str = auto_str.run("Analyze TSLA")
print("String output:", logs_str)
Each instance configures a different output_type during initialization. Invoking run on these instances yields data in the corresponding format—list, dictionary, or string—ready for your specific use case.
Summary
- The AutoHedge class supports three output formats: list, dict, and str.
- The default format is list, returned via
return_messages_as_list(). - Dictionary format provides role-keyed access via
return_messages_as_dictionary(). - String format offers concatenated text via
return_history_as_string(). - Invalid
output_typevalues automatically fall back to list format. - Implementation resides in
autohedge/main.pyin the initialization (lines 15-23) andrunmethod (lines 52-60).
Frequently Asked Questions
What is the default output format for the AutoHedge class?
The default output format is list, which returns message dictionaries in chronological order via self.conversation.return_messages_as_list(). This default is set when output_type is not specified during initialization or when an invalid value is provided.
How does AutoHedge handle unsupported output_type values?
If an unsupported value is passed to the output_type parameter, the run method in autohedge/main.py falls back to the list format. This ensures the system remains robust and always returns usable data even with configuration errors.
Which output format is best for logging conversation history?
The string format (output_type="str") is best for logging because it returns a single concatenated string via return_history_as_string(). This human-readable format is suitable for text files, console output, and monitoring dashboards without requiring additional parsing logic.
Where is the output format logic implemented in the AutoHedge source code?
The output format selection logic is implemented in autohedge/main.py. The __init__ method (lines 15-23) accepts and stores the output_type parameter, while the run method (lines 52-60) contains the conditional logic that routes to the appropriate conversation method based on this 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 →