Commit Graph

21 Commits

Author SHA1 Message Date
Copilot cd655cdae5
feat: concurrent per-ticker pipelines in auto mode, controlled by TRADINGAGENTS_MAX_CONCURRENT_PIPELINES (#103)
* Initial plan

* feat: concurrent per-ticker pipelines in auto mode, configurable via TRADINGAGENTS_MAX_CONCURRENT_PIPELINES

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/464f2038-3a60-4d86-9fe8-4e1cc6943174

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Co-authored-by: ahmet guzererler <guzererler@gmail.com>
2026-03-24 18:08:06 +01:00
Copilot 9c148b208a
Fix: websocket emits "Run completed." on failed runs, masking errors in frontend (#102)
* Initial plan

* Fix websocket sending "Run completed." on failed runs, masking errors from frontend

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/608ea02c-ca85-4f05-9ce1-611802493d7b

* Fix 5 failing unit tests (truthy MagicMock skips) + expose ticker_analyses in state + add Finviz live integration tests

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/7872ceae-cade-4563-aedb-34660d419a36

* docs: update testing.md with MagicMock explainer, current test counts, full catalogue, and detailed run commands

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/13639e60-cb9b-4cb0-891c-df5d448c158d

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
2026-03-24 18:06:48 +01:00
ahmet guzererler 5d5bd4a3cb
feat(ui): scoped graph nodes per ticker + MockEngine for LLM-free UI testing (#100)
* feat(ui): scoped graph nodes per ticker + MockEngine for LLM-free UI testing

## Summary
Adds a MockEngine that streams scripted agent events with zero real LLM calls,
enabling full UI testing (graph, terminal, drawer, metrics) without API keys or
network. Also fixes the ReactFlow graph so that each ticker/identifier gets its
own visual node — previously an auto run with 5 tickers collapsed all pipelines
into the same node IDs, overwriting each other.

## Changes
- **MockEngine** (`agent_os/backend/services/mock_engine.py`): new class that
  generates realistic scripted events for pipeline, scan, and auto run types.
  Supports configurable speed divisor (1× realistic → 10× instant). Auto mock
  accepts a `tickers` list for multi-ticker runs.
- **POST /api/run/mock** (`runs.py`): new endpoint wiring MockEngine into the
  BackgroundTasks + store pattern identical to real run endpoints.
- **WebSocket routing** (`websocket.py`): added `mock` run-type branch so the
  WS executor path also dispatches to MockEngine when the background task hasn't
  started yet.
- **LangGraphEngine** (`langgraph_engine.py`): added `_run_identifiers` dict to
  track ticker/MARKET/portfolio_id per run; all emitted events now carry an
  `identifier` field so the frontend can scope them.
- **AgentGraph.tsx**: ReactFlow nodes now keyed by `node_id:identifier` (e.g.
  `news_analyst:AAPL`, `news_analyst:NVDA`). Edges scoped to same identifier.
  `onNodeClick` passes raw `node_id` + `identifier` separately so the event
  drawer can filter without parsing the scoped key.
- **Dashboard.tsx**: Mock button + type/speed controls added. `openNodeDetail`
  accepts identifier; `NodeEventsDetail` filters by both `node_id` and
  `identifier`. Comma-separated ticker input for mock auto runs (e.g.
  `AAPL,NVDA,TSLA`).
- **useAgentStream.ts**: `AgentEvent` interface extended with `identifier?`
  field.

## Decision Context
- Scoped node ID format chosen as `node_id:identifier` (colon separator) rather
  than embedding identifier in the agent display name — keeps node labels clean
  and identifier visible as a coloured badge, not label text.
- Raw `node_id` and `identifier` stored separately in `node.data` so the drawer
  filtering (`events.filter(e => e.node_id === nodeId && e.identifier === id)`)
  does not need to parse/split the scoped key.
- Parent edges are scoped to the same identifier as the child, assuming intra-
  ticker chains. Cross-run topology edges (e.g. scan → pipeline) are implicit
  via log events, not ReactFlow edges.
- MockEngine uses `asyncio.sleep` with a speed divisor — higher speed values
  give faster replays for rapid iteration during UI development.

## Considerations for Future Agents
- Re-run button on graph nodes already uses `identifier` to dispatch
  `startRun('pipeline', { ticker: identifier })` or `startRun('scan')` — no
  further changes needed for per-node re-runs to be correctly scoped.
- The `_run_identifiers` dict in LangGraphEngine is keyed by `run_id`; it is
  cleaned up after each run. If parallel runs are ever supported per engine
  instance, this dict handles them correctly already.
- For run_auto, each sub-run (scan, per-ticker pipeline) calls its own
  `run_scan`/`run_pipeline` which sets `_run_identifiers[run_id]`. The outer
  `run_auto` does not set it — this is intentional.
- `uv.lock` changes reflect dependency tree after Chainlit removal in the
  previous commit; no new runtime dependencies were added by this PR.

---
🤖 Commit Agent | Session: mock-engine + scoped-graph-nodes

* feat(graph): two-phase column layout — scan top, ticker columns below

## Summary
Redesigns the ReactFlow graph layout engine so scan nodes form a centred funnel
at the top and each ticker gets its own vertical column below, matching the
agreed design. Ticker header cards (bold ticker symbol + pulse dot + progress
counter) act as column anchors; agent cards stack beneath each one. Fan-out
dashed edges connect macro_synthesis → each ticker header.

## Changes
- SCAN phase: geopolitical/market-movers/sector scanners placed on the same
  horizontal row at x = [0, COL_WIDTH, 2×COL_WIDTH] (aligns with first 3
  ticker columns); industry_deep_dive and macro_synthesis centered below.
- TICKER columns: new identifiers get a TickerHeaderNode at tickerStartY;
  agent nodes stack beneath using column-based parent tracking
  (header → agent0 → agent1 → …) independent of evt.parent_node_id.
- TickerHeaderNode: wide card, bold ticker symbol, animated pulse status dot,
  completedCount/agentCount counter updated live as results arrive.
- Tool nodes (node_id starts with "tool_") skipped from graph — visible in
  terminal/drawer, not cluttering the column layout.
- Portfolio nodes centred below all ticker columns.
- Layout state extracted into LayoutState ref + freshLayout() for clean resets.
- Node labels use toLabel() (snake_case → Title Case).
- Metrics row shows total tokens (in+out) instead of just latency.

## Decision Context
- Column-based parent edges chosen over evt.parent_node_id because mock engine
  emits parent_node_id="start" for all agents; column ordering is reliable.
- Scan phase X positions reuse COL_WIDTH so phase-1 scanners visually align
  above first three ticker columns — no arbitrary magic numbers.
- Tool nodes removed from graph (not hidden) — they add noise to column layout
  with no actionable meaning; the drawer already shows them per node.

## Considerations for Future Agents
- identifierLastNode tracks scoped ID of previous agent per ticker column —
  used for sequential edge chaining; do not remove without replacing edge logic.
- tickerStartY is set once on first ticker arrival; subsequent tickers share
  the same Y baseline — only colCount and identifierAgentRow differ per ticker.
- TickerHeaderNode clicks pass node_id='header' + identifier to onNodeClick;
  Dashboard NodeEventsDetail filters all events by identifier when node_id is
  'header' (shows the full ticker run timeline in the drawer).

---
🤖 Commit Agent | Session: two-phase column graph layout
2026-03-24 10:03:16 +01:00
Ahmet Guzererler 80a54b2411 fix: fetch live prices from yfinance when none available for trade execution
The scan summary never contained a 'prices' key, so trade execution always
ran with an empty prices dict. Now prices are fetched via yfinance:

- run_trade_execution: fetches prices for all tickers in the PM decision
  (sells/buys/holds) when prices arg is empty
- run_auto resume path: fetches prices for decision tickers instead of
  reading from scan data
- run_portfolio: fetches prices for current holdings + scan candidates
  before invoking the portfolio graph

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 00:25:51 +01:00
Ahmet Guzererler 0951ef17ec fix: resolve KeyError 'data_dir' when running trade execution
PortfolioRepository expects its own portfolio config (with data_dir),
not DEFAULT_CONFIG. Passing config=self.config caused a KeyError because
DEFAULT_CONFIG has no data_dir key. Removing the argument lets the
repository call get_portfolio_config() which provides the correct defaults.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 00:11:07 +01:00
ahmet guzererler 8461ed540e Fix all review issues 2026-03-23 23:58:51 +01:00
Ahmet Guzererler 57f1d561f9 feat: Add portfolio resumability, extend report saving, and gitignore uv.lock
- Extend run_portfolio to save Holding Reviews, Risk Metrics, PM Decision,
  and Execution Result from final state
- Add run_trade_execution method for resuming trade execution from a saved
  PM decision without re-running the full portfolio graph
- Update run_auto skip logic to check for execution result (not just decision)
  and resume from saved decision when available
- Gitignore uv.lock and untrack it from version control

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-03-23 23:44:34 +01:00
Ahmet Guzererler c2b14dda35 refactor: Remove Chainlit and several other unused dependencies, updating the lock file and related agent configurations. 2026-03-23 23:07:45 +01:00
copilot-swe-agent[bot] c0d13b9207 Fix langgraph engine: fallback ainvoke, portfolio state shape, JSON serialization
Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/43d04354-154a-442c-8bfc-ede05860e7f9
2026-03-23 19:57:35 +00:00
copilot-swe-agent[bot] 9187a69ce2 Fix report saving, event storing, auto tickers, portfolio report loading, and state propagation
Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/9fff2f5e-b384-4b0a-8e23-ede31af12fe2
2026-03-23 18:33:11 +00:00
copilot-swe-agent[bot] 1b5aee572a fix: portfolio field mapping (shares→quantity, cash→cash_balance) and pipeline recursion limit
- Map backend Holding.shares → frontend quantity, include market_value/unrealized_pnl
- Map backend Portfolio.portfolio_id → id, cash → cash_balance
- Map backend Trade.shares → quantity, trade_date → executed_at
- Pass recursion_limit=100 to pipeline astream_events() to prevent GraphRecursionError

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/b189c934-24b9-49a9-99d9-99ee006da4b0
2026-03-23 09:40:56 +00:00
copilot-swe-agent[bot] a77e3f1264 fix: make _map_langgraph_event crash-proof with try/except and _safe_dict
- Wrap each event-type branch (LLM start/end, tool start/end) in try/except
  to prevent a single unexpected object shape from crashing the streaming loop
- Add _safe_dict() helper to guard response_metadata and usage_metadata
  access — some providers return non-dict types (bound methods, etc.)
- Fix potential_text extraction: check for None AND callable before using
- Ensure all event IDs use .get() with fallback to prevent KeyError
- Fix test file: remove hardcoded /Users/Ahmet/ path, add edge-case tests
  for non-dict metadata, tool events, and unknown event types
- All 725 unit tests pass, TypeScript compiles clean

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/fe6575b5-c03b-4037-bd98-a94303ae8313
2026-03-23 09:17:19 +00:00
Ahmet Guzererler 319168c74f feat: Resolve "main_portfolio" alias in portfolio routes and improve LangGraph content extraction robustness with new unit tests. 2026-03-23 10:02:52 +01:00
copilot-swe-agent[bot] 6999da0827 feat: button states, full prompt extraction, portfolio viewer, param inputs
1. Run buttons: only the triggered button shows spinner, others disabled
2. Backend: enhanced prompt extraction with multiple fallback paths
   (data.messages, data.input.messages, data.input, data.kwargs.messages)
   and raw dump fallback; improved response extraction for edge cases
3. Portfolio viewer: new PortfolioViewer component with holdings table,
   trade history, and summary tabs; portfolio dropdown with auto-load;
   Wallet sidebar icon now navigates to portfolio page
4. Parameter inputs: collapsible panel with date/ticker/portfolio_id;
   validation prevents running without required fields per run type

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/ffa268c8-e97c-4335-9bce-19bba583bea9
2026-03-23 08:46:34 +00:00
copilot-swe-agent[bot] b08ce7199e feat: fix prompt display, add event detail modal, run buttons, and node animations
Backend:
- Extract full prompt from all LLM messages (not just first)
- Add prompt/response fields to streamed event payloads
- Improve model name extraction with multiple fallback strategies
- Add run_portfolio and run_auto streaming methods
- Wire portfolio/auto in websocket router
- New tool_result event type for tool completion

Frontend:
- Add full event detail modal with tabs (Prompt, Response, Summary, Metrics)
- Show actual prompt content in drawer instead of "Prompting unknown..."
- Add Scan, Pipeline, Portfolio, Auto buttons to control panel
- Fix node animation: completed nodes never revert to running
- Handle tool_result type for marking tool nodes as done
- Drawer events have "Full Detail →" button to open modal

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/7997c579-ab7e-4071-afd0-18703a8e5618
2026-03-23 08:04:53 +00:00
copilot-swe-agent[bot] 9d2dbf4a43 fix: add missing __init__.py files to agent_os package tree
The agent_os/, agent_os/backend/, agent_os/backend/routes/, and
agent_os/backend/services/ directories were missing __init__.py,
causing `from agent_os.backend.routes import ...` to fail with
ModuleNotFoundError when running `python agent_os/backend/main.py`.

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/4b002166-5cc2-4a75-aa01-14d7b5d8d8bc
2026-03-23 07:16:38 +00:00
copilot-swe-agent[bot] 7726483034 refactor: address code review - extract helpers for content extraction and message parsing
Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/5c511c4e-5172-4eda-b6de-aefa1859e8ac
2026-03-23 00:53:25 +00:00
copilot-swe-agent[bot] e9be24600f fix: AgentOS backend logging/prompts, frontend node persistence, package updates
Backend:
- Replace bare print() with structured logging module
- Include LLM prompt snippets and response content in streamed events
- Extract proper node names from LangGraph metadata (langgraph_node)
- Add latency tracking (start/end time per node)
- Add tool input/output content in events
- Add system log event type for informational messages
- Stream on_tool_end events for tool results

Frontend:
- Fix node disappearing/reappearing: use useNodesState/useEdgesState + useEffect
  for incremental updates instead of useMemo that rebuilt all nodes on each event
- Fix duplicate node creation: use useRef to track seen node IDs persistently
- Fix useAgentStream reconnection loop: remove stale `status` from connect deps
- Use statusRef to avoid stale closure in onclose handler
- Add auto-scroll to terminal, event count, type labels/colors
- Show prompt snippets, tool I/O, and response content in terminal
- Handle 'log' event type

Packages:
- Update all npm deps to latest compatible minor versions
- Remove node_modules from git tracking, add to .gitignore

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/5c511c4e-5172-4eda-b6de-aefa1859e8ac
2026-03-23 00:51:29 +00:00
Ahmet Guzererler c9e5e8989f fix: align report paths and improve node name mapping for live streaming
- update portfolio summary route to check 'summary/' directory for scan results
- enhance LangGraph event mapping to extract functional node names from metadata
- fix initial state keys for ScannerGraph to match TradingAgents internals
2026-03-22 22:46:21 +01:00
Ahmet Guzererler 078d7e2f2a feat: implement AgentOS frontend and live backend integration
- scaffold Vite + React + TypeScript frontend with Chakra UI and React Flow
- implement AgentGraph, MetricHeader, and Dashboard components
- connect FastAPI to live LangGraph events via astream_events
- implement real-time event mapping for 'scan' and 'pipeline'
- refactor run storage for shared access between REST and WebSockets
2026-03-22 22:12:33 +01:00
Ahmet Guzererler a26c93463a feat: initialize AgentOS observability foundation
- implement FastAPI backend with REST and WebSocket streaming
- add node-level metrics (tokens, latency) to event protocol
- design literal graph and top 3 metrics (Sharpe, Regime, Drawdown)
- scaffold React frontend with Chakra UI and useAgentStream hook
- add DESIGN.md and .env.example
2026-03-22 21:54:13 +01:00