feat: remove /reasoning endpoint (replaced by /results)

- Delete Pydantic models: ReasoningMessage, PositionSummary, TradingSessionResponse, ReasoningResponse
- Delete /reasoning endpoint from api/main.py
- Remove /reasoning documentation from API_REFERENCE.md
- Delete old endpoint tests (test_api_reasoning_endpoint.py)
- Add integration tests verifying /results replaces /reasoning

The /reasoning endpoint has been replaced by /results with reasoning parameter:
- GET /reasoning?job_id=X -> GET /results?job_id=X&reasoning=summary
- GET /reasoning?job_id=X&include_full_conversation=true -> GET /results?job_id=X&reasoning=full

Benefits of new endpoint:
- Day-centric structure (easier to understand portfolio progression)
- Daily P&L metrics included
- AI-generated reasoning summaries
- Unified data model (trading_days, actions, holdings)
This commit is contained in:
2025-11-04 09:58:39 -05:00
parent 60ea9ab802
commit 9c1c96d4f6
4 changed files with 100 additions and 770 deletions

View File

@@ -665,241 +665,6 @@ curl "http://localhost:8080/results?job_id=550e8400-e29b-41d4-a716-446655440000&
---
### GET /reasoning
Retrieve AI reasoning logs for simulation days with optional filters. Returns trading sessions with positions and optionally full conversation history including all AI messages, tool calls, and responses.
**Query Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `job_id` | string | No | Filter by job UUID |
| `date` | string | No | Filter by trading date (YYYY-MM-DD) |
| `model` | string | No | Filter by model signature |
| `include_full_conversation` | boolean | No | Include all messages and tool calls (default: false, only returns summaries) |
**Response (200 OK) - Summary Only (default):**
```json
{
"sessions": [
{
"session_id": 1,
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"date": "2025-01-16",
"model": "gpt-4",
"session_summary": "Agent analyzed market conditions, purchased 10 shares of AAPL at $250.50, and 5 shares of MSFT at $380.20. Total portfolio value increased to $10,105.00.",
"started_at": "2025-01-16T10:00:05Z",
"completed_at": "2025-01-16T10:05:23Z",
"total_messages": 8,
"positions": [
{
"action_id": 1,
"action_type": "buy",
"symbol": "AAPL",
"amount": 10,
"price": 250.50,
"cash_after": 7495.00,
"portfolio_value": 10000.00
},
{
"action_id": 2,
"action_type": "buy",
"symbol": "MSFT",
"amount": 5,
"price": 380.20,
"cash_after": 5594.00,
"portfolio_value": 10105.00
}
],
"conversation": null
}
],
"count": 1,
"deployment_mode": "PROD",
"is_dev_mode": false,
"preserve_dev_data": null
}
```
**Response (200 OK) - With Full Conversation:**
```json
{
"sessions": [
{
"session_id": 1,
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"date": "2025-01-16",
"model": "gpt-4",
"session_summary": "Agent analyzed market conditions, purchased 10 shares of AAPL at $250.50, and 5 shares of MSFT at $380.20. Total portfolio value increased to $10,105.00.",
"started_at": "2025-01-16T10:00:05Z",
"completed_at": "2025-01-16T10:05:23Z",
"total_messages": 8,
"positions": [
{
"action_id": 1,
"action_type": "buy",
"symbol": "AAPL",
"amount": 10,
"price": 250.50,
"cash_after": 7495.00,
"portfolio_value": 10000.00
},
{
"action_id": 2,
"action_type": "buy",
"symbol": "MSFT",
"amount": 5,
"price": 380.20,
"cash_after": 5594.00,
"portfolio_value": 10105.00
}
],
"conversation": [
{
"message_index": 0,
"role": "user",
"content": "You are a trading agent. Current date: 2025-01-16. Cash: $10000.00. Previous positions: {}. Yesterday's prices: {...}",
"summary": null,
"tool_name": null,
"tool_input": null,
"timestamp": "2025-01-16T10:00:05Z"
},
{
"message_index": 1,
"role": "assistant",
"content": "I'll analyze the market and make trading decisions...",
"summary": "Agent analyzes market conditions and decides to purchase AAPL",
"tool_name": null,
"tool_input": null,
"timestamp": "2025-01-16T10:00:12Z"
},
{
"message_index": 2,
"role": "tool",
"content": "{\"status\": \"success\", \"symbol\": \"AAPL\", \"shares\": 10, \"price\": 250.50}",
"summary": null,
"tool_name": "trade",
"tool_input": "{\"action\": \"buy\", \"symbol\": \"AAPL\", \"amount\": 10}",
"timestamp": "2025-01-16T10:00:13Z"
},
{
"message_index": 3,
"role": "assistant",
"content": "Trade executed successfully. Now purchasing MSFT...",
"summary": "Agent confirms AAPL purchase and initiates MSFT trade",
"tool_name": null,
"tool_input": null,
"timestamp": "2025-01-16T10:00:18Z"
}
]
}
],
"count": 1,
"deployment_mode": "PROD",
"is_dev_mode": false,
"preserve_dev_data": null
}
```
**Response Fields:**
| Field | Type | Description |
|-------|------|-------------|
| `sessions` | array[object] | Array of trading sessions |
| `count` | integer | Number of sessions returned |
| `deployment_mode` | string | Deployment mode: "PROD" or "DEV" |
| `is_dev_mode` | boolean | True if running in development mode |
| `preserve_dev_data` | boolean\|null | DEV mode only: whether dev data is preserved between runs |
**Trading Session Fields:**
| Field | Type | Description |
|-------|------|-------------|
| `session_id` | integer | Unique session ID |
| `job_id` | string | Job UUID this session belongs to |
| `date` | string | Trading date (YYYY-MM-DD) |
| `model` | string | Model signature |
| `session_summary` | string | High-level summary of AI decisions and actions |
| `started_at` | string | ISO 8601 timestamp when session started |
| `completed_at` | string | ISO 8601 timestamp when session completed |
| `total_messages` | integer | Total number of messages in conversation |
| `positions` | array[object] | All trading actions taken this day |
| `conversation` | array[object]\|null | Full message history (null unless `include_full_conversation=true`) |
**Position Summary Fields:**
| Field | Type | Description |
|-------|------|-------------|
| `action_id` | integer | Action sequence number (1, 2, 3...) for this session |
| `action_type` | string | Action taken: `buy`, `sell`, or `hold` |
| `symbol` | string | Stock symbol traded (or null for `hold`) |
| `amount` | integer | Quantity traded (or null for `hold`) |
| `price` | float | Price per share (or null for `hold`) |
| `cash_after` | float | Cash balance after this action |
| `portfolio_value` | float | Total portfolio value (cash + holdings) |
**Reasoning Message Fields:**
| Field | Type | Description |
|-------|------|-------------|
| `message_index` | integer | Message sequence number starting from 0 |
| `role` | string | Message role: `user`, `assistant`, or `tool` |
| `content` | string | Full message content |
| `summary` | string\|null | Human-readable summary (for assistant messages only) |
| `tool_name` | string\|null | Tool name (for tool messages only) |
| `tool_input` | string\|null | Tool input parameters (for tool messages only) |
| `timestamp` | string | ISO 8601 timestamp |
**Error Responses:**
**400 Bad Request** - Invalid date format
```json
{
"detail": "Invalid date format: 2025-1-16. Expected YYYY-MM-DD"
}
```
**404 Not Found** - No sessions found matching filters
```json
{
"detail": "No trading sessions found matching the specified criteria"
}
```
**Examples:**
All sessions for a specific job (summaries only):
```bash
curl "http://localhost:8080/reasoning?job_id=550e8400-e29b-41d4-a716-446655440000"
```
Sessions for a specific date with full conversation:
```bash
curl "http://localhost:8080/reasoning?date=2025-01-16&include_full_conversation=true"
```
Sessions for a specific model:
```bash
curl "http://localhost:8080/reasoning?model=gpt-4"
```
Combine filters to get full conversation for specific model-day:
```bash
curl "http://localhost:8080/reasoning?job_id=550e8400-e29b-41d4-a716-446655440000&date=2025-01-16&model=gpt-4&include_full_conversation=true"
```
**Use Cases:**
- **Debugging AI decisions**: Examine full conversation history to understand why specific trades were made
- **Performance analysis**: Review session summaries to identify patterns in successful trading strategies
- **Model comparison**: Compare reasoning approaches between different AI models on the same trading day
- **Audit trail**: Document AI decision-making process for compliance or research purposes
- **Strategy refinement**: Analyze tool usage patterns and message sequences to optimize agent prompts
---
### GET /health
Health check endpoint for monitoring and orchestration services.