Skip to content

Fix/example - #88

Merged
Iamsdt merged 6 commits into
mainfrom
fix/example
Apr 3, 2026
Merged

Fix/example#88
Iamsdt merged 6 commits into
mainfrom
fix/example

Conversation

@Iamsdt

@Iamsdt Iamsdt commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

This pull request introduces several important improvements to the LLM adapters in the agentflow.runtime.adapters.llm package, focusing on lazy loading of converters, improved type checking, and a major refactor of the OpenAIConverter to enhance maintainability and streaming support. The changes also include minor fixes and code quality improvements across the runtime module.

LLM Adapter Refactoring and Improvements

Lazy Import and API Surface Changes:

  • The agentflow.runtime.adapters.llm package now uses lazy loading for concrete converter implementations, exposing a minimal, stable API surface and avoiding import cycles during test collection. This is achieved by removing eager imports and adding a __getattr__ for dynamic attribute access. [1] [2]

Type Checking and Imports:

  • Introduced from __future__ import annotations and conditional imports with TYPE_CHECKING in several modules (base_converter.py, model_response_converter.py) to improve type safety and avoid unnecessary runtime imports. [1] [2]

OpenAI Converter Refactor

Major Refactor of OpenAIConverter:

  • The convert_response method in openai_converter.py was refactored for clarity and maintainability. Extraction of usage, message content, reasoning, audio, images, and tool calls is now handled by dedicated helper methods, reducing duplication and improving readability. [1] [2] [3]
  • Streaming response handling was restructured: chunk processing is now more modular, with new methods for iterating over async/sync streams, extracting reasoning, and building content blocks. This results in more robust and maintainable streaming support. [1] [2] [3]

Delegation and Import Fixes:

  • The code for delegating to the OpenAIResponsesConverter is now cleaner, with imports moved to the top and redundant code removed. [1] [2]

Minor Improvements and Housekeeping

Code Quality and Compatibility:

  • Fixed __all__ construction in agentflow/runtime/__init__.py for compatibility.
  • Added a dataclass import in openai_responses_converter.py for future extensibility.
  • Suppressed linter warnings for the Agent class constructor parameter count.

These changes collectively improve the modularity, maintainability, and testability of the LLM adapter subsystem, while laying groundwork for future extensions and better streaming support.

Iamsdt added 6 commits April 3, 2026 20:45
…t logic, and enhance tool integration

- Deleted unused example files: react_sync.py, test_react_sync.py, react_di2.py, stop_stream_litellm.py, stream1.py.
- Refactored react_di.py to improve imports and structure.
- Updated react_mcp.py to utilize the Agent class for main agent logic.
- Streamlined stream-related examples to use the Agent class for better clarity and maintainability.
- Enhanced tool invocation and response handling across various examples.
…arity; update imports and enhance streaming response handling
- Updated import paths in various test files to reflect the transition from 'agentflow' to 'agentflow.runtime' and 'agentflow.storage'.
- Adjusted mock patches in tests to ensure compatibility with the new structure, particularly in OpenAI, Google, and Redis embedding tests.
- Ensured that all relevant tests are correctly referencing the updated module paths for consistent functionality.
@codecov

codecov Bot commented Apr 3, 2026

Copy link
Copy Markdown

@Iamsdt
Iamsdt merged commit 9fa69ea into main Apr 3, 2026
5 of 6 checks passed
@Iamsdt
Iamsdt deleted the fix/example branch April 3, 2026 16:27
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