How to Start the AutoHedge Interactive REPL: Command-Line Guide
Run the autohedge command in your terminal after installing the package to launch the interactive REPL, which invokes the run_repl() function from autohedge/cli.py and accepts natural language task prompts for portfolio hedging analysis.
The AutoHedge interactive REPL provides a command-line interface for analyzing portfolio allocations and hedging strategies through conversational prompts. According to the source code in The-Swarm-Corporation/AutoHedge, starting the REPL requires invoking the package's command-line entry point, which initializes the AutoHedge core class and begins processing user inputs. This guide covers the exact commands, prerequisites, and internal mechanisms required to launch and use the REPL effectively.
Prerequisites for Starting the AutoHedge REPL
Install the Package from PyPI
Before launching the REPL, install AutoHedge using pip. The package registers the autohedge console script that maps to the CLI module.
pip install -U autohedge
Configure Environment Variables
The REPL requires API keys for external language model services. While the REPL will start without them—emitting warnings about missing configuration—full functionality requires proper environment setup. Create a .env file based on the repository's .env.example or export variables directly:
export OPENAI_API_KEY="your-api-key-here"
The autohedge/env_loader.py module handles loading these variables when the REPL initializes.
Command-Line Methods to Start the REPL
Using the autohedge Command
The primary method to start the AutoHedge interactive REPL is running the entry-point command installed with the package. This invokes run_repl() defined in autohedge/cli.py (lines 44-46):
autohedge
Using Python Module Execution
Alternatively, execute the package as a module using Python's -m flag. This approach calls autohedge/__main__.py, which forwards execution to the same CLI entry point:
python -m autohedge
Both methods instantiate the AutoHedge class from autohedge/main.py and present the interactive prompt.
Internal Architecture of the REPL Startup
When you execute the startup command, the following sequence occurs according to the source code:
- Argument Parsing: The CLI module in
autohedge/cli.pybuilds anArgumentParserto handle command-line options. - REPL Initialization: The
run_repl()function (lines 44-46 inautohedge/cli.py) displays the welcome banner and enters the input loop. - Core Class Loading: User inputs are passed to the
AutoHedgeclass defined inautohedge/main.py, specifically itsrunmethod, which processes the task prompts and returns JSON-formatted recommendations. - Environment Setup: The
autohedge/env_loader.pymodule loads API keys and configuration variables before processing begins.
Using the AutoHedge REPL
Entering Task Prompts
Once started, the REPL displays a welcome banner and accepts natural language prompts for portfolio analysis. For example:
> Analyze NVDA for 50k allocation
[dim]Running...[/]
Result
──────
<JSON-formatted recommendation from AutoHedge>
Exiting the Session
Terminate the REPL session by typing any of the following commands followed by Enter:
quitexitq
The input handler in autohedge/cli.py checks for these specific strings to break the execution loop and return control to your shell.
Summary
- Install AutoHedge via
pip install -U autohedgeto access theautohedgecommand used to start the interactive REPL. - Launch methods include running
autohedgedirectly orpython -m autohedge, both invokingrun_repl()inautohedge/cli.py. - Configure environment variables like
OPENAI_API_KEYin a.envfile or shell exports before starting (handled byautohedge/env_loader.py). - Exit the session by typing
quit,exit, orqat the prompt. - The REPL processes commands through the
AutoHedgeclass inautohedge/main.py, returning JSON-formatted hedging recommendations for your queries.
Frequently Asked Questions
What is the AutoHedge interactive REPL?
The AutoHedge interactive REPL is a command-line interface provided by The-Swarm-Corporation/AutoHedge that accepts natural language prompts for portfolio analysis and hedging strategies. It runs in a continuous loop defined in autohedge/cli.py, processing user inputs through the AutoHedge.run() method and returning structured JSON recommendations.
Do I need an OpenAI API key to start the REPL?
No, the REPL will start without the OPENAI_API_KEY environment variable set, displaying warnings about missing configuration but remaining functional. Set the key in a .env file or export it in your shell to enable full language model functionality, as the autohedge/env_loader.py module attempts to load these variables during initialization.
How do I exit the AutoHedge REPL safely?
Type quit, exit, or q at the prompt and press Enter. The run_repl() function in autohedge/cli.py explicitly checks for these specific input strings to terminate the input loop gracefully and return you to the shell without raising errors.
Can I run the AutoHedge REPL without installing via pip?
Yes, if you clone the repository, you can run python -m autohedge from the project root directory. The autohedge/__main__.py file provides this entry point, which calls the same cli.main() function used by the installed autohedge command, allowing you to start the REPL directly from source.
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 →