Commit Graph

2040 Commits

Author SHA1 Message Date
Greyson LaLonde
4921b71e8b fix: re-record VCR cassette for async LLM test 2026-01-22 22:56:15 -05:00
Greyson LaLonde
8be27da9ff docs: add README and description for crewai-files package 2026-01-22 22:50:10 -05:00
Greyson LaLonde
2c5e794ea3 feat: allow LLM providers to pass clients to file uploaders
- Add get_file_uploader() method to BaseLLM (returns None by default)
- Implement get_file_uploader() in Anthropic, OpenAI, Gemini, Bedrock
- Pass both sync and async clients where applicable
- Update uploaders to accept optional pre-instantiated clients
- Update factory to pass through client parameters

This allows reusing authenticated LLM clients for file uploads,
avoiding redundant connections.
2026-01-22 22:44:05 -05:00
Greyson LaLonde
9a2b610b21 fix: handle optional crewai_files import in types.py 2026-01-22 22:33:58 -05:00
Greyson LaLonde
19d6a47d0c fix: support multimodal content in Bedrock message formatting
- Add format_text_content override for Bedrock's {"text": ...} format
- Handle pre-formatted list content in _format_messages_for_converse
- Update Bedrock tests to use Claude 3 Haiku for on-demand availability
- Add VCR cassettes for Bedrock multimodal tests
2026-01-22 22:27:58 -05:00
Greyson LaLonde
83bab3531b test: add Gemini multimodal integration test cassettes
Record VCR cassettes for Gemini multimodal tests and add missing
TextFile import.
2026-01-22 22:14:41 -05:00
Greyson LaLonde
11b50abbec test: add multimodal integration test cassettes
Record VCR cassettes for OpenAI, Anthropic, Azure, and LiteLLM
multimodal tests. Gemini and Bedrock tests remain but cassettes
will be generated when credentials are available.
2026-01-22 22:12:20 -05:00
Greyson LaLonde
a1cbb2f4e2 refactor: improve multimodal file handling architecture
- Make crewai_files an optional dependency with graceful fallbacks
- Move file formatting from executor to LLM layer (_process_message_files)
- Add files field to LLMMessage type for cleaner message passing
- Add cache_control to Anthropic content blocks for prompt caching
- Clean up formatters: static methods for OpenAI/Gemini, proper error handling
- Remove unused ContentFormatter protocol
- Move test fixtures to lib/crewai-files/tests/fixtures
- Add Azure and Bedrock multimodal integration tests
- Fix mypy errors in crew_agent_executor.py
2026-01-22 21:55:10 -05:00
Greyson LaLonde
dc015b14f9 Merge branch 'main' into gl/feat/native-multimodal-files 2026-01-22 20:47:35 -05:00
Lorenze Jay
bd4d039f63 Lorenze/imp/native tool calling (#4258)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Notify Downstream / notify-downstream (push) Waiting to run
* wip restrcuturing agent executor and liteagent

* fix: handle None task in AgentExecutor to prevent errors

Added a check to ensure that if the task is None, the method returns early without attempting to access task properties. This change improves the robustness of the AgentExecutor by preventing potential errors when the task is not set.

* refactor: streamline AgentExecutor initialization by removing redundant parameters

Updated the Agent class to simplify the initialization of the AgentExecutor by removing unnecessary task and crew parameters in standalone mode. This change enhances code clarity and maintains backward compatibility by ensuring that the executor is correctly configured without redundant assignments.

* wip: clean

* ensure executors work inside a flow due to flow in flow async structure

* refactor: enhance agent kickoff preparation by separating common logic

Updated the Agent class to introduce a new private method  that consolidates the common setup logic for both synchronous and asynchronous kickoff executions. This change improves code clarity and maintainability by reducing redundancy in the kickoff process, while ensuring that the agent can still execute effectively within both standalone and flow contexts.

* linting and tests

* fix test

* refactor: improve test for Agent kickoff parameters

Updated the test for the Agent class to ensure that the kickoff method correctly preserves parameters. The test now verifies the configuration of the agent after kickoff, enhancing clarity and maintainability. Additionally, the test for asynchronous kickoff within a flow context has been updated to reflect the Agent class instead of LiteAgent.

* refactor: update test task guardrail process output for improved validation

Refactored the test for task guardrail process output to enhance the validation of the output against the OpenAPI schema. The changes include a more structured request body and updated response handling to ensure compliance with the guardrail requirements. This update aims to improve the clarity and reliability of the test cases, ensuring that task outputs are correctly validated and feedback is appropriately provided.

* test fix cassette

* test fix cassette

* working

* working cassette

* refactor: streamline agent execution and enhance flow compatibility

Refactored the Agent class to simplify the execution method by removing the event loop check and clarifying the behavior when called from synchronous and asynchronous contexts. The changes ensure that the method operates seamlessly within flow methods, improving clarity in the documentation. Additionally, updated the AgentExecutor to set the response model to None, enhancing flexibility. New test cassettes were added to validate the functionality of agents within flow contexts, ensuring robust testing for both synchronous and asynchronous operations.

* fixed cassette

* Enhance Flow Execution Logic

- Introduced conditional execution for start methods in the Flow class.
- Unconditional start methods are prioritized during kickoff, while conditional starts are executed only if no unconditional starts are present.
- Improved handling of cyclic flows by allowing re-execution of conditional start methods triggered by routers.
- Added checks to continue execution chains for completed conditional starts.

These changes improve the flexibility and control of flow execution, ensuring that the correct methods are triggered based on the defined conditions.

* Enhance Agent and Flow Execution Logic

- Updated the Agent class to automatically detect the event loop and return a coroutine when called within a Flow, simplifying async handling for users.
- Modified Flow class to execute listeners sequentially, preventing race conditions on shared state during listener execution.
- Improved handling of coroutine results from synchronous methods, ensuring proper execution flow and state management.

These changes enhance the overall execution logic and user experience when working with agents and flows in CrewAI.

* Enhance Flow Listener Logic and Agent Imports

- Updated the Flow class to track fired OR listeners, ensuring that multi-source OR listeners only trigger once during execution. This prevents redundant executions and improves flow efficiency.
- Cleared fired OR listeners during cyclic flow resets to allow re-execution in new cycles.
- Modified the Agent class imports to include Coroutine from collections.abc, enhancing type handling for asynchronous operations.

These changes improve the control and performance of flow execution in CrewAI, ensuring more predictable behavior in complex scenarios.

* adjusted test due to new cassette

* ensure native tool calling works with liteagent

* ensure response model is respected

* Enhance Tool Name Handling for LLM Compatibility

- Added a new function  to replace invalid characters in function names with underscores, ensuring compatibility with LLM providers.
- Updated the  function to sanitize tool names before validation.
- Modified the  function to use sanitized names for tool registration.

These changes improve the robustness of tool name handling, preventing potential issues with invalid characters in function names.

* ensure we dont finalize batch on just a liteagent finishing

* max tools per turn wip and ensure we drop print times

* fix sync main issues

* fix llm_call_completed event serialization issue

* drop max_tools_iterations

* for fixing model dump with state

* Add extract_tool_call_info function to handle various tool call formats

- Introduced a new utility function  to extract tool call ID, name, and arguments from different provider formats (OpenAI, Gemini, Anthropic, and dictionary).
- This enhancement improves the flexibility and compatibility of tool calls across multiple LLM providers, ensuring consistent handling of tool call information.
- The function returns a tuple containing the call ID, function name, and function arguments, or None if the format is unrecognized.

* Refactor AgentExecutor to support batch execution of native tool calls

- Updated the  method to process all tools from  in a single batch, enhancing efficiency and reducing the number of interactions with the LLM.
- Introduced a new utility function  to streamline the extraction of tool call details, improving compatibility with various tool formats.
- Removed the  parameter, simplifying the initialization of the .
- Enhanced logging and message handling to provide clearer insights during tool execution.
- This refactor improves the overall performance and usability of the agent execution flow.

* Update English translations for tool usage and reasoning instructions

- Revised the `post_tool_reasoning` message to clarify the analysis process after tool usage, emphasizing the need to provide only the final answer if requirements are met.
- Updated the `format` message to simplify the instructions for deciding between using a tool or providing a final answer, enhancing clarity for users.
- These changes improve the overall user experience by providing clearer guidance on task execution and response formatting.

* fix

* fixing azure tests

* organizae imports

* dropped unused

* Remove debug print statements from AgentExecutor to clean up the code and improve readability. This change enhances the overall performance of the agent execution flow by eliminating unnecessary console output during LLM calls and iterations.

* linted

* updated cassette

* regen cassette

* revert crew agent executor

* adjust cassettes and dropped tests due to native tool implementation

* adjust

* ensure we properly fail tools and emit their events

* Enhance tool handling and delegation tracking in agent executors

- Implemented immediate return for tools with result_as_answer=True in crew_agent_executor.py.
- Added delegation tracking functionality in agent_utils.py to increment delegations when specific tools are used.
- Updated tool usage logic to handle caching more effectively in tool_usage.py.
- Enhanced test cases to validate new delegation features and tool caching behavior.

This update improves the efficiency of tool execution and enhances the delegation capabilities of agents.

* Enhance tool handling and delegation tracking in agent executors

- Implemented immediate return for tools with result_as_answer=True in crew_agent_executor.py.
- Added delegation tracking functionality in agent_utils.py to increment delegations when specific tools are used.
- Updated tool usage logic to handle caching more effectively in tool_usage.py.
- Enhanced test cases to validate new delegation features and tool caching behavior.

This update improves the efficiency of tool execution and enhances the delegation capabilities of agents.

* fix cassettes

* fix

* regen cassettes

* regen gemini

* ensure we support bedrock

* supporting bedrock

* regen azure cassettes

* Implement max usage count tracking for tools in agent executors

- Added functionality to check if a tool has reached its maximum usage count before execution in both crew_agent_executor.py and agent_executor.py.
- Enhanced error handling to return a message when a tool's usage limit is reached.
- Updated tool usage logic in tool_usage.py to increment usage counts and print current usage status.
- Introduced tests to validate max usage count behavior for native tool calling, ensuring proper enforcement and tracking.

This update improves tool management by preventing overuse and providing clear feedback when limits are reached.

* fix other test

* fix test

* drop logs

* better tests

* regen

* regen all azure cassettes

* regen again placeholder for cassette matching

* fix: unify tool name sanitization across codebase

* fix: include tool role messages in save_last_messages

* fix: update sanitize_tool_name test expectations

Align test expectations with unified sanitize_tool_name behavior
that lowercases and splits camelCase for LLM provider compatibility.

* fix: apply sanitize_tool_name consistently across codebase

Unify tool name sanitization to ensure consistency between tool names
shown to LLMs and tool name matching/lookup logic.

* regen

* fix: sanitize tool names in native tool call processing

- Update extract_tool_call_info to return sanitized tool names
- Fix delegation tool name matching to use sanitized names
- Add sanitization in crew_agent_executor tool call extraction
- Add sanitization in experimental agent_executor
- Add sanitization in LLM.call function lookup
- Update streaming utility to use sanitized names
- Update base_agent_executor_mixin delegation check

* Extract text content from parts directly to avoid warning about non-text parts

* Add test case for Gemini token usage tracking

- Introduced a new YAML cassette for tracking token usage in Gemini API responses.
- Updated the test for Gemini to validate token usage metrics and response content.
- Ensured proper integration with the Gemini model and API key handling.

---------

Co-authored-by: Greyson LaLonde <greyson.r.lalonde@gmail.com>
2026-01-22 17:44:03 -08:00
Greyson LaLonde
7d03758c83 fix: use typing_extensions.TypedDict for Python < 3.12 compatibility 2026-01-22 20:27:50 -05:00
Greyson LaLonde
bbdb383529 Merge branch 'lorenze/imp/native-tool-calling' into gl/feat/native-multimodal-files 2026-01-22 20:22:30 -05:00
Greyson LaLonde
4bd32f6626 fix: import Self from typing_extensions for Python 3.10 compatibility 2026-01-22 20:16:25 -05:00
lorenzejay
69bc9a5897 Extract text content from parts directly to avoid warning about non-text parts 2026-01-22 17:12:17 -08:00
Greyson LaLonde
4decb15c61 Merge branch 'lorenze/imp/native-tool-calling' into gl/feat/native-multimodal-files 2026-01-22 20:09:53 -05:00
Greyson LaLonde
80f7410683 Merge branch 'lorenze/imp/native-tool-calling' of https://github.com/crewAIInc/crewAI into lorenze/imp/native-tool-calling 2026-01-22 20:05:41 -05:00
Greyson LaLonde
b104d64b39 fix: sanitize tool names in native tool call processing
- Update extract_tool_call_info to return sanitized tool names
- Fix delegation tool name matching to use sanitized names
- Add sanitization in crew_agent_executor tool call extraction
- Add sanitization in experimental agent_executor
- Add sanitization in LLM.call function lookup
- Update streaming utility to use sanitized names
- Update base_agent_executor_mixin delegation check
2026-01-22 20:05:20 -05:00
lorenzejay
a54005459d Merge branch 'lorenze/imp/native-tool-calling' of github.com:crewAIInc/crewAI into lorenze/imp/native-tool-calling 2026-01-22 16:53:16 -08:00
lorenzejay
ec3a65b529 regen 2026-01-22 16:53:00 -08:00
Greyson LaLonde
242757f67b fix: apply sanitize_tool_name consistently across codebase
Unify tool name sanitization to ensure consistency between tool names
shown to LLMs and tool name matching/lookup logic.
2026-01-22 19:52:25 -05:00
Greyson LaLonde
8310ca1369 fix: update sanitize_tool_name test expectations
Align test expectations with unified sanitize_tool_name behavior
that lowercases and splits camelCase for LLM provider compatibility.
2026-01-22 19:17:42 -05:00
Greyson LaLonde
1b006beedc Merge branch 'main' into gl/feat/native-multimodal-files 2026-01-22 19:14:55 -05:00
Greyson LaLonde
edae4e889c fix: include tool role messages in save_last_messages 2026-01-22 19:10:33 -05:00
Greyson LaLonde
846133310b fix: unify tool name sanitization across codebase 2026-01-22 19:01:14 -05:00
lorenzejay
e9ca6e89d8 regen again placeholder for cassette matching 2026-01-22 14:49:07 -08:00
lorenzejay
11c96d6e3c regen all azure cassettes 2026-01-22 14:14:21 -08:00
lorenzejay
f1bad9c748 regen 2026-01-22 14:09:16 -08:00
lorenzejay
73963b8e65 better tests 2026-01-22 14:08:02 -08:00
lorenzejay
249b118e9e drop logs 2026-01-22 13:54:27 -08:00
lorenzejay
51c5973033 fix test 2026-01-22 13:52:38 -08:00
lorenzejay
c7a83c8c36 fix other test 2026-01-22 13:47:52 -08:00
lorenzejay
ba15fbf8ea Implement max usage count tracking for tools in agent executors
- Added functionality to check if a tool has reached its maximum usage count before execution in both crew_agent_executor.py and agent_executor.py.
- Enhanced error handling to return a message when a tool's usage limit is reached.
- Updated tool usage logic in tool_usage.py to increment usage counts and print current usage status.
- Introduced tests to validate max usage count behavior for native tool calling, ensuring proper enforcement and tracking.

This update improves tool management by preventing overuse and providing clear feedback when limits are reached.
2026-01-22 13:47:36 -08:00
lorenzejay
90ab4d2527 regen azure cassettes 2026-01-22 13:40:10 -08:00
lorenzejay
65746137fe supporting bedrock 2026-01-22 13:31:56 -08:00
lorenzejay
89e961e08e ensure we support bedrock 2026-01-22 13:29:49 -08:00
lorenzejay
a61cfb258f regen gemini 2026-01-22 13:02:14 -08:00
Greyson LaLonde
ca07114bcf refactor: centralize multimodal formatting in crewai_files 2026-01-22 15:59:55 -05:00
lorenzejay
2f300bf86e regen cassettes 2026-01-22 12:49:56 -08:00
lorenzejay
f3951cb09d fix 2026-01-22 12:36:05 -08:00
Greyson LaLonde
b95a3a9bc8 refactor: extract files module to standalone crewai-files package 2026-01-22 15:06:20 -05:00
lorenzejay
77697c3ad9 fix cassettes 2026-01-22 11:43:07 -08:00
lorenzejay
a0fad289c5 Enhance tool handling and delegation tracking in agent executors
- Implemented immediate return for tools with result_as_answer=True in crew_agent_executor.py.
- Added delegation tracking functionality in agent_utils.py to increment delegations when specific tools are used.
- Updated tool usage logic to handle caching more effectively in tool_usage.py.
- Enhanced test cases to validate new delegation features and tool caching behavior.

This update improves the efficiency of tool execution and enhances the delegation capabilities of agents.
2026-01-22 11:42:52 -08:00
lorenzejay
458f6867f0 Enhance tool handling and delegation tracking in agent executors
- Implemented immediate return for tools with result_as_answer=True in crew_agent_executor.py.
- Added delegation tracking functionality in agent_utils.py to increment delegations when specific tools are used.
- Updated tool usage logic to handle caching more effectively in tool_usage.py.
- Enhanced test cases to validate new delegation features and tool caching behavior.

This update improves the efficiency of tool execution and enhances the delegation capabilities of agents.
2026-01-22 11:35:27 -08:00
Greyson LaLonde
a064b84ead feat: add URL file source support for multimodal content 2026-01-22 14:18:16 -05:00
Greyson LaLonde
4d0b6d834c test: add real video file tests for duration detection 2026-01-22 14:08:40 -05:00
Greyson LaLonde
9be88e05ee feat: add format hints to audio/video duration detection 2026-01-22 14:02:55 -05:00
lorenzejay
d0af4c6331 ensure we properly fail tools and emit their events 2026-01-22 10:36:11 -08:00
lorenzejay
0d4ff5d80c adjust 2026-01-22 10:18:35 -08:00
lorenzejay
a6a0bf6412 adjust cassettes and dropped tests due to native tool implementation 2026-01-22 10:15:18 -08:00
lorenzejay
bffe5aa877 revert crew agent executor 2026-01-22 09:28:00 -08:00