Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/crewai/agents/crew_agent_executor.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I don't think get_context_window_size will return the true context size for llm backed by ollama.

Khalid,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, thank you for replying do you have any inputs to make it work for ollama as well?

Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ def _invoke_loop(self) -> AgentFinish:

enforce_rpm_limit(self.request_within_rpm_limit)

# Pre-handle context length just before calling the LLM
try:
window_size = self.llm.get_context_window_size()
except Exception:
window_size = None
if window_size is not None:
total_len = sum(len(m.get("content", "")) for m in self.messages)
if total_len >= window_size:
handle_context_length(
respect_context_window=self.respect_context_window,
printer=self._printer,
messages=self.messages,
llm=self.llm,
callbacks=self.callbacks,
i18n=self._i18n,
)

answer = get_llm_response(
llm=self.llm,
messages=self.messages,
Expand Down