Skip to content

Refactor ProcessRequest across all interception types #200

@ssncferreira

Description

@ssncferreira

Description

All six ProcessRequest implementations (blocking + streaming for chatcompletions, messages, and responses) follow the same high-level flow, but each reimplements it independently, making the code hard to follow and difficult to unit test.

Goals:

  • Identify the common flow that ProcessRequest follows across all implementations, and ensure the code and comments clearly reflect it
  • Extract shared logic into helper methods on each interception type's base type (provider-specific refactor, not a generic abstraction)
  • Fix bugs and inconsistencies discovered during the refactor
  • Improve unit testability: extracting helpers onto the base types means each step of the flow (tool call classification, tool invocation, result appending, usage recording) can be tested in isolation, without requiring full HTTP round-trip setup

The responses implementation has already partially accomplished this by extracting the agentic loop and recording logic into methods on the base type. The same pattern should be applied to messages and chatcompletions.

Suggested order of work:

  • messages (Anthropic); most duplication, most complexity
  • chatcompletions (OpenAI): follows the same pattern, should be mechanical after Anthropic
  • responses (OpenAI): review for consistency

Sub-issues

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions