Skip to content

Fix/llm optimizations#123

Merged
Iamsdt merged 4 commits into
mainfrom
fix/llm_optimizations
May 22, 2026
Merged

Fix/llm optimizations#123
Iamsdt merged 4 commits into
mainfrom
fix/llm_optimizations

Conversation

@Iamsdt
Copy link
Copy Markdown
Collaborator

@Iamsdt Iamsdt commented May 22, 2026

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:

  • Added a new call_llm function in agentflow/core/llm/caller.py that 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))
  • Updated agentflow/core/llm/__init__.py to export call_llm alongside 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:

  • Improved handling of explicit cache content for Google LLM calls: if a cache is used, the system instruction is not resent, and cache hits are logged. ([[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))
  • Enhanced OpenAI API call methods to log cache hits and extract cache token usage from responses, both for chat completions and responses APIs. ([[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:

  • Updated agentflow/core/state/__init__.py to export SummaryContextManager, 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))

Iamsdt added 4 commits May 22, 2026 16:33
…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

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
@Iamsdt Iamsdt merged commit a443a1f into main May 22, 2026
5 of 6 checks passed
@Iamsdt Iamsdt deleted the fix/llm_optimizations branch May 22, 2026 13:40
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