Add reflections as a background task
This commit is contained in:
parent
341d81079f
commit
baf74ff197
|
|
@ -8,4 +8,5 @@ eval_data/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
.env
|
.env
|
||||||
trading_agents/
|
trading_agents/
|
||||||
web_app/frontend/node_modules/*
|
web_app/frontend/node_modules/*
|
||||||
|
*.pdf
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 186 KiB |
|
|
@ -29,4 +29,5 @@ pydantic
|
||||||
python-multipart
|
python-multipart
|
||||||
python-jose[cryptography]
|
python-jose[cryptography]
|
||||||
passlib[bcrypt]
|
passlib[bcrypt]
|
||||||
python-dotenv
|
python-dotenv
|
||||||
|
pygraphviz
|
||||||
|
|
@ -382,8 +382,8 @@ async def get_jobs():
|
||||||
|
|
||||||
return {"jobs": job_lst}
|
return {"jobs": job_lst}
|
||||||
|
|
||||||
@app.post("/reflect-on-analysis/{symbol}/{date}")
|
@app.post("/reflect-on-analysis/{symbol}/{date}", response_model=AnalysisResponse)
|
||||||
async def reflect_on_analysis(symbol: str, date: str, request: dict):
|
async def reflect_on_analysis(symbol: str, date: str, request: dict, background_tasks: BackgroundTasks):
|
||||||
"""Get latest financial situation memory for a specific analysis"""
|
"""Get latest financial situation memory for a specific analysis"""
|
||||||
returns_losses = request.get("returns_losses")
|
returns_losses = request.get("returns_losses")
|
||||||
if returns_losses is None:
|
if returns_losses is None:
|
||||||
|
|
@ -402,40 +402,15 @@ async def reflect_on_analysis(symbol: str, date: str, request: dict):
|
||||||
if not matching_job:
|
if not matching_job:
|
||||||
raise HTTPException(status_code=404, detail=f"No active job found for {symbol} on {date}")
|
raise HTTPException(status_code=404, detail=f"No active job found for {symbol} on {date}")
|
||||||
|
|
||||||
matching_job.trading_agent.reflect_and_remember(returns_losses)
|
background_tasks.add_task(
|
||||||
|
matching_job.trading_agent.reflect_and_remember, returns_losses
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
return AnalysisResponse(
|
||||||
bull_memory = matching_job.trading_agent.bull_memory
|
job_id=matching_job.job_id,
|
||||||
bear_memory = matching_job.trading_agent.bear_memory
|
status="reflecting",
|
||||||
trader_memory = matching_job.trading_agent.trader_memory
|
message=f"Reflecting on analysis for {symbol} on {date}"
|
||||||
invest_judge_memory = matching_job.trading_agent.invest_judge_memory
|
)
|
||||||
risk_manager_memory = matching_job.trading_agent.risk_manager_memory
|
|
||||||
|
|
||||||
reflections = {}
|
|
||||||
|
|
||||||
latest_entry = bull_memory.get_latest_situation()
|
|
||||||
reflections["bull_memory"] = latest_entry
|
|
||||||
|
|
||||||
latest_entry = bear_memory.get_latest_situation()
|
|
||||||
reflections["bear_memory"] = latest_entry
|
|
||||||
|
|
||||||
latest_entry = trader_memory.get_latest_situation()
|
|
||||||
reflections["trader_memory"] = latest_entry
|
|
||||||
|
|
||||||
latest_entry = invest_judge_memory.get_latest_situation()
|
|
||||||
reflections["invest_judge_memory"] = latest_entry
|
|
||||||
|
|
||||||
latest_entry = risk_manager_memory.get_latest_situation()
|
|
||||||
reflections["risk_manager_memory"] = latest_entry
|
|
||||||
|
|
||||||
return {
|
|
||||||
"symbol": symbol.upper(),
|
|
||||||
"date": date,
|
|
||||||
"job_id": matching_job.job_id,
|
|
||||||
"reflections": reflections
|
|
||||||
}
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=500, detail=f"Error retrieving latest situation: {str(e)}")
|
|
||||||
|
|
||||||
@app.get("/config")
|
@app.get("/config")
|
||||||
async def get_default_config():
|
async def get_default_config():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue