File size: 1,648 Bytes
da605e9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # Agent App
## Run the UI
```bash
cd /Users/binx/Desktop/Goon/agent
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
streamlit run app/app.py
```
Set your Anthropic key in `agent/.env`:
```bash
ANTHROPIC_API_KEY=your_key_here
```
Or paste it into the sidebar after the app starts.
## Local Python API
This repo does not expose an HTTP API server. The supported programmatic interface is the local Python function in `analysis.agent`.
### Basic usage
```python
from analysis.agent import run_agent
result = run_agent("How many posts per subreddit?")
print(result["answer"])
print(result["tool_calls"])
```
### With prior context
```python
from analysis.agent import run_agent
turns = [
{
"question": "How many posts per subreddit?",
"answer": "Previous answer text",
"tool_calls": [],
"artifacts": [],
"plotly_json": "",
"route": "describe",
}
]
result = run_agent(
"Which subreddits changed most over time?",
turns=turns,
)
print(result["route"])
print(result["answer"])
```
## Return shape
`run_agent(...)` returns a dictionary with:
- `answer`: final assistant response
- `tool_calls`: executed tool calls plus arguments and results
- `plotly_json`: chart payload when a plot was generated
- `route`: detected route for the question
- `allowed_tools`: tools exposed for that route
## Notes
- Use `python3`, not `python`, in this environment.
- The app stores structured turn state in the Streamlit session so follow-up questions can reuse prior analytical context.
- Generated CSV and PNG artifacts are written to `agent/outputs/`.
|