You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CLAUDE: agent_map list output (return_table) (#5531)
## Summary
CLAUDE: Adds a `return_list` (api_v0) / `return_table` (SDK) option to
`agent_map`, mirroring the existing flag on `single_agent`. When
enabled, each per-row agent emits a list of records that fans out into
multiple output rows (with an `_expand_index` column).
This restores the "map + expand" capability that earlier Cohort code
exposed. The internal `AgentQueryParams.is_expand` path and ClickHouse
partial-table ingestion already supported MAP+expand for the autocohort
path — only the public API surface gated it off.
### Changes
**Engine (api_v0):**
- `data_types/operations.py` — added `return_list: bool = False` field
to `AgentMapOperation` (mirrors `SingleAgentOperation`).
- `conversions.py` — both request types now flow `return_list →
AgentQueryParams.is_expand`. Removed the explicit
`isinstance(SingleAgentOperation)` gate.
**SDK:**
- `ops.py` — threaded `return_table: bool = False` through `agent_map`,
`agent_map_async`, and `_submit_agent_map`. Forwards as `return_list` on
the wire and flips `EveryrowTask.is_expand` so the result is unpacked
correctly.
- `generated/models/agent_map_operation.py` — regenerated from the
updated OpenAPI spec.
- `README.md` — added a `return_table=True` example.
**Tests:**
- 4 new handler tests on `/operations/agent-map` (default false,
explicit false, explicit true, column-collision contract under
`join_with_input=True`).
- 5 new unit tests on `agent_operation_to_agent_query_params` covering
both request types.
- Replaced misleading `test_agent_map_with_table_output` (didn't
actually exercise the flag) with two tests asserting `return_list` is
forwarded and the result fans out (3 items × 2 input rows → 6 output
rows).
### What's not in this PR
- **SDK version bump.** Per the `bump-sdk-version` skill, version bumps
go in their own dedicated PR. Should be a follow-up after this lands.
### Schema contract (worth calling out)
When `return_table=True`, users pass the **per-item** `response_schema`
— not a pre-wrapped `{items: [...]}` schema. The worker calls
`wrap_json_schema_in_list` at execution time; ClickHouse unwraps via
`_extract_item_schema`. Documented in the field description and SDK
docstring.
## Test plan
- [x] `uv run pytest tests/server/api_v0/test_operations.py
tests/server/api_v0/test_conversions.py` — 136 passed
- [x] `uv run pytest tests/test_ops.py` (futuresearch-python) — 13
passed
- [x] `uv run ruff check` and `uv run pyright` clean on touched files
- [ ] Smoke-test against staging once merged: submit an `agent_map` with
`return_list=true` and a small per-item schema, confirm row count >
input row count and `_expand_index` column is present.
- [ ] Autocohort regression spot-check — same `query_params` shape lands
in DB regardless of submission path, but worth running the autocohort
tests.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sourced from commit 09d429c61cfb923102ed411a88d641af6699b1dc
Copy file name to clipboardExpand all lines: README.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,6 +84,18 @@ result = await agent_map(
84
84
]),
85
85
)
86
86
print(result.data.head())
87
+
88
+
# Same map, but each agent emits a list of records that fan out into extra rows
89
+
# (one row per item, with an `_expand_index` column).
90
+
result =await agent_map(
91
+
task="List this company's top 5 products",
92
+
input=DataFrame([
93
+
{"company": "Anthropic"},
94
+
{"company": "OpenAI"},
95
+
]),
96
+
return_table=True,
97
+
)
98
+
print(result.data.head())
87
99
```
88
100
89
101
See the API [docs](https://futuresearch.ai/docs/reference/RESEARCH), a case study of [labeling data](https://futuresearch.ai/docs/classify-dataframe-rows-llm) or a case study for [researching government data](https://futuresearch.ai/docs/case-studies/research-and-rank-permit-times) at scale.
0 commit comments