Skip to content

Conversation

rkirkendall
Copy link

Modernizes agent action generation to use strict structured outputs.

Summary

  • Uses Responses API JSON Schema in responses mode; falls back to Pydantic parse in legacy mode.
  • Surfaces explicit refusal; prefers typed parsed payload over post-parse JSON.

Why

  • Consistent, typed outputs across models and modes.
  • Unlocks strict schema validation and better failure handling.
  • Backward compatible with legacy path.

Scope

  • Only core agent path + client plumbing. No notebooks or examples included.

Changes

  • tinytroupe/agent/action_generator.py: Send JSON Schema with strict=true (derived from CognitiveActionModel / CognitiveActionModelWithReasoning) when API_MODE=responses; prefer parsed; handle refusal.
  • tinytroupe/openai_utils.py: API_MODE=responses|legacy; map to responses.create/parse (max_output_tokens, reasoning.effort); unified extractor returning role/content/parsed/refusal.
  • tests/unit/test_action_generator_structured_outputs.py: Tests for parsed-preference and refusal handling.

Backward compatibility

  • Legacy path unchanged; schema enforced only when requested.

Testing

  • Unit tests pass locally.

Notes

Follow-ups

  • PR3: Enrichment structured outputs.
  • PR4: Extraction/Normalizer structured outputs.

rkirkendall and others added 11 commits August 30, 2025 10:02
- Added configuration option for API_MODE in config.ini to enable Responses API for local runs.
- Updated OpenAIClient to handle both 'responses' and 'legacy' modes, preserving existing behavior while allowing for new functionality.
- Implemented parameter mapping for Responses API, ensuring compatibility with legacy chat parameters.

This change aims to improve flexibility in API usage and facilitate a smoother transition to the new Responses API.
- Updated response extraction logic to prefer typed parsed output when available.
…or to prefer structured responses and handle model refusals more gracefully.
- Added configuration option for API_MODE in config.ini to enable Responses API for local runs.
- Updated OpenAIClient to handle both 'responses' and 'legacy' modes, preserving existing behavior while allowing for new functionality.
- Implemented parameter mapping for Responses API, ensuring compatibility with legacy chat parameters.

This change aims to improve flexibility in API usage and facilitate a smoother transition to the new Responses API.
- Updated response extraction logic to prefer typed parsed output when available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant