Commit Graph

406 Commits

Author SHA1 Message Date
Greyson LaLonde
a9cea10df0 Merge branch 'main' into chore/runtime-state-event-bus 2026-04-07 02:28:58 +08:00
Greyson LaLonde
ac0a4b2bd9 fix: make BaseTool survive checkpoint JSON round-trip
BaseTool could not serialize to JSON because args_schema (a class
reference) and cache_function (a lambda) are not JSON-serializable.
This caused checkpointing to crash for any crew with tools.

- Add PlainSerializer to args_schema so it round-trips via JSON schema
- Replace default cache_function lambda with named _default_cache_function
  and type it as SerializableCallable
- Add computed_field tool_type storing the fully qualified class name
- Add __init_subclass__ registry and __get_pydantic_core_schema__ on
  BaseTool so any list[BaseTool] field automatically dispatches to the
  concrete subclass during deserialization via tool_type lookup
- No changes needed to BaseAgent.validate_tools or Task — Pydantic
  handles it natively through the custom core schema
2026-04-07 02:27:21 +08:00
Greyson LaLonde
7c3b987037 fix: make BaseTool survive checkpoint JSON round-trip
BaseTool could not serialize to JSON because args_schema (a class
reference) and cache_function (a lambda) are not JSON-serializable.
This caused checkpointing to crash for any crew with tools.

- Add PlainSerializer to args_schema so it round-trips via JSON schema
- Replace default cache_function lambda with named _default_cache_function
  and type it as SerializableCallable so it serializes to a dotted path
- Add computed_field tool_type that stores the fully qualified class name
- Add restore_tool_from_dict to reconstruct the concrete subclass from
  checkpoint dicts, pre-resolving callback strings to callables
- Update BaseAgent.validate_tools and Task._restore_tools_from_checkpoint
  to handle dict inputs from checkpoint deserialization
2026-04-07 02:14:03 +08:00
alex-clawd
bf2f4dbce6 fix: exclude embedding vectors from memory serialization (saves tokens) (#5298)
Some checks failed
Build uv cache / build-cache (3.11) (push) Has been cancelled
Build uv cache / build-cache (3.12) (push) Has been cancelled
Build uv cache / build-cache (3.13) (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Vulnerability Scan / pip-audit (push) Has been cancelled
Build uv cache / build-cache (3.10) (push) Has been cancelled
* fix: exclude embedding vector from MemoryRecord serialization

MemoryRecord.embedding (1536 floats for OpenAI embeddings) was included
in model_dump()/JSON serialization and repr. When recall results flow
to agents or get logged, these vectors burn tokens for zero value —
agents never need the raw embedding.

Added exclude=True and repr=False to the embedding field. The storage
layer accesses record.embedding directly (not via model_dump), so
persistence is unaffected.

* test: validate embedding excluded from serialization

Two tests:
1. MemoryRecord — model_dump, model_dump_json, and repr all exclude
   embedding. Direct attribute access still works for storage layer.
2. MemoryMatch — nested record serialization also excludes embedding.
2026-04-06 14:48:58 -03:00
Greyson LaLonde
14d5d5bbf8 fix: accumulate all prior task outputs when skipping on checkpoint resume 2026-04-07 00:48:10 +08:00
Greyson LaLonde
3ceeda3aa4 Merge branch 'main' into chore/runtime-state-event-bus
# Conflicts:
#	lib/crewai/src/crewai/llms/providers/openai/completion.py
#	lib/devtools/pyproject.toml
#	uv.lock
2026-04-07 00:45:42 +08:00
Lorenze Jay
fdb9b6f090 fix: bump litellm to >=1.83.0 to address CVE-2026-35030
* fix: bump litellm to >=1.83.0 to address CVE-2026-35030

Bump litellm from <=1.82.6 to >=1.83.0 to fix JWT auth bypass via
OIDC cache key collision (CVE-2026-35030). Also widen devtools openai
pin from ~=1.83.0 to >=1.83.0,<3 to resolve the version conflict
(litellm 1.83.0 requires openai>=2.8.0).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: resolve mypy errors from litellm bump

- Remove unused type: ignore[import-untyped] on instructor import
- Remove all unused type: ignore[union-attr] comments (litellm types fixed)
- Add hasattr guard for tool_call.function — new litellm adds
  ChatCompletionMessageCustomToolCall to the union which lacks .function

* fix: tighten litellm pin to ~=1.83.0 (patch-only bumps)

>=1.83.0,<2 is too wide — litellm has had breaking changes between
minors. ~=1.83.0 means >=1.83.0,<1.84.0 — gets CVE patches but won't
pull in breaking minor releases.

* ci: bump uv from 0.8.4 to 0.11.3

* fix: resolve mypy errors in openai completion from 2.x type changes

Use isinstance checks with concrete openai response types instead of
string comparisons for proper type narrowing. Update code interpreter
handling for outputs/OutputImage API changes in openai 2.x.

* fix: pre-cache tiktoken encoding before VCR intercepts requests

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Alex <alex@crewai.com>
Co-authored-by: Greyson LaLonde <greyson@crewai.com>
2026-04-07 00:41:20 +08:00
Greyson LaLonde
c9c3ac8dcc fix: serialize args_schema as JSON schema for checkpoint roundtrip
Use BeforeValidator/PlainSerializer with create_model_from_schema to
serialize type[BaseModel] as its JSON schema dict and reconstruct a
dynamic model on deserialization.
2026-04-07 00:04:45 +08:00
Greyson LaLonde
07aa7c0558 fix: skip create_agent_executor for resuming agents 2026-04-06 23:51:21 +08:00
Greyson LaLonde
54897bbc77 fix: restore type[BaseModel] | None on CrewStructuredTool.args_schema 2026-04-06 23:34:40 +08:00
Greyson LaLonde
d2b092a77e fix: clear error messages for missing llm_type/executor_type 2026-04-06 22:32:33 +08:00
Greyson LaLonde
594e1d4876 fix: restore emission counter from checkpoint event record 2026-04-06 22:23:06 +08:00
Greyson LaLonde
57cd9cf5d4 fix: aemit skips ContextVar scope mutations, only records events 2026-04-06 22:10:55 +08:00
Greyson LaLonde
9235edc096 feat: preserve event subtypes through checkpoint serialization
- Add Literal type discriminators to all 119 event subclasses
- Add BeforeValidator + PlainSerializer on EventNode.event to
  deserialize events into the correct subclass using a type registry
- Falls back to BaseEvent for unrecognized or incomplete event dicts
2026-04-06 21:52:32 +08:00
Greyson LaLonde
61422be7cf fix: populate task_id on task events and match in scope restore
Set task_id and task_name in _set_task_fingerprint so events carry
task identity through serialization. Use task_id to find the correct
task_started event when restoring the scope stack on checkpoint resume.
2026-04-06 21:17:33 +08:00
Greyson LaLonde
b55e86ac8c fix: only restore crew-level scope on checkpoint resume 2026-04-06 21:06:09 +08:00
Greyson LaLonde
e5452d5e70 fix: use json mode in RuntimeState entity serialization 2026-04-06 20:59:32 +08:00
Greyson LaLonde
6aa6d275f6 Merge branch 'main' into chore/runtime-state-event-bus
# Conflicts:
#	uv.lock
2026-04-06 20:49:59 +08:00
Greyson LaLonde
408cd045e4 cleanup: remove dead _entity_discriminator and CheckpointPayload 2026-04-06 20:47:41 +08:00
Greyson LaLonde
4e15d49176 fix: wire executor back-references in BaseAgent.from_checkpoint 2026-04-06 20:45:57 +08:00
Greyson LaLonde
ef7654d7d5 fix: add RWLock to EventRecord for thread-safe concurrent access 2026-04-06 20:44:55 +08:00
Greyson LaLonde
470af2f9e1 feat: add llm_type and executor_type discriminators for checkpoint fidelity
Add type discriminator fields to BaseLLM subclasses and
BaseAgentExecutor subclasses so checkpoint deserialization restores
the correct provider class instead of always creating LLM/CrewAgentExecutor.
2026-04-06 20:32:19 +08:00
Greyson LaLonde
97866c68ce fix: pre-cache tiktoken encoding before VCR intercepts requests 2026-04-06 19:37:03 +08:00
Greyson LaLonde
e1bbab75b3 fix: eliminate PydanticSerializationUnexpectedValue warnings
Switch RuntimeState serializer from mode="wrap" to mode="plain" with
dict return type so pydantic doesn't re-serialize entities through the
Entity union pipeline. Also switch to string-based field discriminator
for Entity union.
2026-04-06 19:23:15 +08:00
João Moura
c393bd2ee6 feat: bump versions to 1.14.0a3 (#5295) 2026-04-06 05:17:10 -03:00
João Moura
c907ce473b feat: bump versions to 1.14.0a2 (#5293) 2026-04-06 04:33:37 -03:00
João Moura
e46402d10d feat: bump versions to 1.14.0a1 (#5292)
* chore: update uv.lock with new dependency groups and versioning adjustments

- Added a new revision number and updated resolution markers for Python version compatibility.
- Introduced a 'dev' dependency group with specific versions for various development tools.
- Updated sdist and wheels entries to include upload timestamps for better tracking.
- Adjusted numpy dependencies to specify versions based on Python version markers.

* feat: bump versions to 1.14.0a1
2026-04-06 04:32:20 -03:00
Lorenze Jay
bce10f5978 fix: ensure output directory exists before writing in flow template (#5291)
The `save_content` method wrote to `output/post.md` without ensuring the
`output/` directory exists, causing a FileNotFoundError when the directory
hasn't been created by another step.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 22:21:18 -07:00
Lorenze Jay
d2e57e375b updating poem to content use case (#5286)
* updating poem to content use case

* addressing CVE-2026-35030
2026-04-05 22:05:02 -07:00
Greyson LaLonde
167b609365 fix: restore event scope stack from checkpoint event record
Replay the event record during _restore_runtime to rebuild
_event_id_stack with correct event IDs. Remove manual push_event_scope
calls from task and crew resume paths that used task UUIDs instead
of event IDs.
2026-04-04 23:18:23 +08:00
Greyson LaLonde
b46e96532e fix: return state messages by reference, not copy 2026-04-04 23:06:07 +08:00
Greyson LaLonde
5c243b72a8 fix: skip adding crew-owned agents as top-level RuntimeState entities 2026-04-04 23:03:50 +08:00
Greyson LaLonde
055d1469a0 fix: resolve mypy errors from openai 2.x type changes 2026-04-04 23:00:49 +08:00
Greyson LaLonde
6e7afb732f fix: avoid duplicating LLM hooks on checkpoint restore 2026-04-04 22:41:59 +08:00
Greyson LaLonde
e0fc32144c fix: return 0 instead of None when checkpoint resumes from first task 2026-04-04 22:37:42 +08:00
Greyson LaLonde
0c228b45b7 fix: seed _registered_entity_ids from restored RuntimeState 2026-04-04 22:31:39 +08:00
Greyson LaLonde
3f447f21d0 cleanup: remove redundant _registered_entity_ids class annotation 2026-04-04 22:27:32 +08:00
Greyson LaLonde
da5a890eae fix: share event metadata setup between emit and aemit
Extract _prepare_event to set previous_event_id, triggered_by_event_id,
emission_sequence, parent/child scoping, and event_record tracking.
Both emit and aemit now call it, fixing aemit's missing metadata.
2026-04-04 22:24:58 +08:00
Greyson LaLonde
686cff6514 fix: register entities in aemit like emit does 2026-04-04 22:12:19 +08:00
Greyson LaLonde
fac186a931 fix: handle unhashable partial handlers in param count cache 2026-04-04 22:10:09 +08:00
Greyson LaLonde
70fc701941 fix: bump litellm to ~=1.83.0 and openai to ~=2.30.0
litellm 1.83.0 fixes CVE-2026-35029 (proxy config privilege escalation)
and CVE-2026-35030 (proxy JWT auth bypass), and is the first release
after the supply chain incident. Bump openai to 2.x to satisfy litellm's
dependency.
2026-04-04 22:04:16 +08:00
Greyson LaLonde
c4bbb039da refactor: use lru_cache for handler param count 2026-04-04 21:35:00 +08:00
Greyson LaLonde
d769469ff6 fix: restore checkpoint_train flag during checkpoint resume 2026-04-04 21:30:36 +08:00
Greyson LaLonde
ebb58a237e fix: bump uv-pre-commit to 0.11.3, distinguish checkpoint resume
- Bump uv-pre-commit from 0.9.3 to 0.11.3 to support relative
  exclude-newer values in pyproject.toml
- Use checkpoint_kickoff_event_id to detect resume, preventing
  second kickoff() from skipping tasks or suppressing events
2026-04-04 21:29:30 +08:00
Greyson LaLonde
b882988128 fix: checkpoint resume bugs and handler signature caching
- Return len(tasks) from _get_execution_start_index when all tasks
  complete, preventing full re-execution of finished checkpoints
- Add _get_execution_start_index call to _aexecute_tasks so async
  resume skips completed tasks like the sync path does
- Cache inspect.signature results per handler to avoid repeated
  introspection on every event emission
2026-04-04 04:11:34 +08:00
Greyson LaLonde
81e51f058a Merge branch 'main' into chore/runtime-state-event-bus 2026-04-04 04:01:50 +08:00
Greyson LaLonde
e72b08ec49 fix: resolve mypy errors from optional executor fields
- Disable union-attr/arg-type at file level in the two executor files
  where agent/task/crew are always set at runtime but typed as optional
- Fix Liskov override in OpenAICompletion: use BaseAgent instead of Agent
- Remove stale type: ignore comments now covered by file-level disables
2026-04-04 03:57:39 +08:00
Greyson LaLonde
c1f9d9270b fix: assign mocks post-init for remaining executor tests
Remove spec= from mocks and construct executors with defaults, then
assign mock agent/task/crew after init to avoid pydantic validation.
2026-04-04 03:38:46 +08:00
Greyson LaLonde
a94c2bf786 fix: bypass pydantic validation for mocks in BaseAgentExecutor tests
After model_rebuild, BaseAgentExecutor rejects plain MagicMock for
typed fields. Construct with defaults then assign mocks post-init.
Also guard RuntimeState tests for environments where model_rebuild fails.
2026-04-04 03:33:07 +08:00
Greyson LaLonde
206259b537 fix: add spec= to remaining mocks passed to pydantic models 2026-04-04 03:12:21 +08:00