Fix/llm optimizations#123
Merged
Merged
Conversation
…ation with token-budget support feat: add call_llm utility for single-turn LLM calls, centralizing provider dispatch refactor: update __init__.py files to include new context manager and utility imports test: add unit tests for SummaryContextManager functionality and behavior
…d add related configurations
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import AsyncMock, MagicMock, patch |
|
|
||
| from agentflow.core.state.agent_state import AgentState | ||
| from agentflow.core.state.message import Message | ||
| from agentflow.core.state.message_block import TextBlock, ToolCallBlock, ToolResultBlock |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a shared utility for making single-turn LLM calls (
call_llm), centralizing logic that was previously duplicated across several modules. It also adds improved cache handling and logging for both Google and OpenAI LLM providers, and updates module exports to surface the new utility and related classes. The changes improve code reuse, simplify future maintenance, and enhance observability of cache hits.Key changes include:
Shared LLM Call Utility:
call_llmfunction inagentflow/core/llm/caller.pythat abstracts single-turn LLM calls for both Google and OpenAI, handling provider detection, system prompts, JSON mode, and cache support. This utility returns a tuple with the generated text and token usage statistics. ([agentflow/core/llm/caller.pyR1-R275](https://github.com/10xHub/Agentflow/pull/123/files#diff-82566d5139e0b7b2848b16f7b04915b14919caf110df4f89b05347b264583b2eR1-R275))agentflow/core/llm/__init__.pyto exportcall_llmalongside the existing client factory utilities. ([agentflow/core/llm/__init__.pyR3-R7](https://github.com/10xHub/Agentflow/pull/123/files#diff-ad245908c6f01b3a0914880a56645148d6deaef6c6250a34e56badc6cd62c3a9R3-R7))Cache Handling and Observability:
[[1]](https://github.com/10xHub/Agentflow/pull/123/files#diff-e3191b678bfb7cbad630798c0122a01b62134f674c62fc09a90c492e2f3d7135L307-L309),[[2]](https://github.com/10xHub/Agentflow/pull/123/files#diff-e3191b678bfb7cbad630798c0122a01b62134f674c62fc09a90c492e2f3d7135R315-R321),[[3]](https://github.com/10xHub/Agentflow/pull/123/files#diff-e3191b678bfb7cbad630798c0122a01b62134f674c62fc09a90c492e2f3d7135L373-R387),[[4]](https://github.com/10xHub/Agentflow/pull/123/files#diff-e3191b678bfb7cbad630798c0122a01b62134f674c62fc09a90c492e2f3d7135R410-R427))[[1]](https://github.com/10xHub/Agentflow/pull/123/files#diff-c14055d8309966d71807222c92629294b7e68eb3d788da4657baf196e21311c8L104-R133),[[2]](https://github.com/10xHub/Agentflow/pull/123/files#diff-c14055d8309966d71807222c92629294b7e68eb3d788da4657baf196e21311c8L226-R254))Module Exports and State Management:
agentflow/core/state/__init__.pyto exportSummaryContextManager, making it available for import elsewhere in the codebase. ([[1]](https://github.com/10xHub/Agentflow/pull/123/files#diff-2e3404ad0021e70d98d93d1257fe333381b405bb71aba7f05dff7e4b13bd03f6R42),[[2]](https://github.com/10xHub/Agentflow/pull/123/files#diff-2e3404ad0021e70d98d93d1257fe333381b405bb71aba7f05dff7e4b13bd03f6R66))