Skip to content

The CrewAI Bot is a CrewAI conversational Agent - #2636

Open
lorenzejay wants to merge 12 commits into
CopilotKit:mainfrom
lorenzejay:crewai-conversational-agent
Open

lorenzejay wants to merge 12 commits into
CopilotKit:mainfrom
lorenzejay:crewai-conversational-agent

Conversation

@lorenzejay

@lorenzejay lorenzejay commented Dec 1, 2026 •

Copy link
Copy Markdown

What this changes

The CrewAI Bot now answers through CrewAI's conversational Agent (Agent(conversational=True)), served by ag-ui-crewai's conversational mode (add_crewai_flow_fastapi_endpoint(..., conversational=True)). Before, it called the model directly from a one-step CrewAI Flow. The goal is that a standalone conversational CrewAI Agent works as the agent-crewai engine, with everything the Bot on main does.

What the Bot keeps doing. The Bot's role, the whole thread, and OpenBot's tools reach it as before. Replies still arrive whole, not word by word (see Not in this PR).

What the conversational path needed (all in agent-crewai/src/main.py):

  • System and developer messages. ag-ui-crewai's conversational path drops every system message of a run. The Bot keeps them for the Agent, each where it was in the thread: the role first, a note from the middle of the thread after the turn it followed. It also keeps developer messages, and leaves them out of CrewAI's session, whose messages have no such role. Before, a run with one failed with a ValidationError.
  • Tools the server runs. CrewAI runs an Agent's tools itself, but the server runs OpenBot's tools. Each AG-UI tool becomes a CrewAI tool that records the call and ends the turn. The turn's reply is the model's own call, with its id, under the server's name for the tool. CrewAI shows the model sanitize_tool_name(name), so showBarChart reaches it as show_bar_chart. The Bot names the tool that way and hands the call back as showBarChart; askApproval and mcp__… tools work the same way. Numbered names for tools that collide stay within 64 characters. A turn whose call can't be matched to a tool fails rather than reply with the stand-in's text.
  • Tool schemas. OpenBot's tools are offered with their own schema and strict mode off, as the Bot on main sends them. CrewAI's strict mode closes every object, so an artifact's content or a patch's value could only be {}. A format other than a date or time is left out, and tuple-style items become one schema. No Pydantic model is built from the schema, so a format: email field (manage_people) or tuple-style items no longer fail the run.
  • Tool arguments. The nulls a tool's own schema did not allow are taken out of the handed-back call.
  • Words with a tool call. CrewAI keeps a step that called tools with no content, so a line on a long job never reached the person. The words the model streamed in that step become the reply's content.
  • Message ids. ag-ui-crewai gave every earlier message a new id in its snapshots, so the app showed the conversation twice. The session keeps each message's AG-UI id.
  • The model client. CrewAI calls OpenAI, Anthropic and Google models through their own SDKs. The provider is named explicitly, because given openai/<model> CrewAI sends a model it has not heard of (Gemini on the model gateway, qwen/qwen3-8b on a local server) to LiteLLM, which offered it no tools. An empty OPENAI_BASE_URL or ANTHROPIC_BASE_URL, as Compose writes for a plain key, is treated as unset. A model OpenAI serves only on the Responses API (gpt-5.3-codex) is moved there: CrewAI does this only for an older wording of OpenAI's 404. Any other provider still goes through LiteLLM.
  • Pinned. crewai==1.15.41 (the version shared/model-lock.json records) and ag-ui-crewai==1.0.0. The Bot relies on parts of both that neither publishes; a test checks each is still there, so an upgrade comes through CI.
  • Quiet logs. CrewAI's console panels for every Flow and Agent are off; errors and the trace link still reach the log.
  • From main, kept.

docs/agent-frameworks.md lists what a conversational CrewAI Agent needs, for anyone building their own, and points at main.py as a reference rather than a file to copy.

Not in this PR.

  • Streaming. CrewAI streams the model's tokens, but ag-ui-crewai 1.0.0 drops CrewAI's own llm_stream_chunk events, so replies arrive whole. That fix belongs in ag-ui-crewai.
  • Adapter and CrewAI internals. The Bot patches ag-ui-crewai's crewai_prepare_inputs and is_backend_tool_event, and CrewAI's tool-schema conversion and Responses-API check. Each is worth fixing upstream (a per-tool strict flag in CrewAI; the newer 404 wording), after which the patches can go.
  • Gemini signatures. Reading the signature at the HTTP layer goes away once CrewAI's OpenAI client keeps extra_content on tool calls.

Where it runs

  • New state that outlives a request? None. The Bot keeps nothing between runs: the server sends the whole thread each run, and the Agent is built for the turn.
  • What happens on the second replica? The same answer: any replica can take any run.
  • Anything serialised? No.
  • Anything fanned out to a browser? No; the Bot answers on its AG-UI stream as before.
  • New listener, port, or schedule? No; the Bot serves on 4202 as before.

Boundary and audit

  • Every acting call still goes through the gateway: the Bot hands each call back; the server runs it.
  • No new refusals or failures on the server.
  • Nothing new is trusted from the client.

API and database

  • This changes nothing under api/, no app's requests, no database change and no release-policy.json.

Changelog

Bots.

  • The CrewAI Bot is a CrewAI Agent. A Bot on the CrewAI engine now answers through CrewAI's conversational Agent (Agent(conversational=True)), served by ag-ui-crewai's conversational mode. Before, it called the model directly from a one-step CrewAI Flow. The Bot's role, the whole thread and OpenBot's tools reach it as they did, and its replies still arrive whole rather than word by word. CrewAI now calls OpenAI, Anthropic and Google models through their own SDKs, and any other model through LiteLLM as before.

Proof

  • python -m pytest agent-crewai/tests, as CI runs it (fresh venv, pip install of both requirements files, crewai 1.15.41): 66 passed. The same tests against this branch before the review fixes: 18 failed, including the run with OpenBot's real tool schemas, which ended in RUN_ERROR (ImportError, the email field).

  • Live, this branch's Bot on crewai 1.15.41 with OpenBot's real artifact_create, artifact_patch and manage_people schemas, two turns each (the call handed back, its result sent back, the answer finished):

    Model Path create patch manage_people
    gpt-5.5 Chat Completions ✅ content: {"markdown": …} ✅ value: 42 ✅
    gpt-6-astra Responses (tools) ✅ ✅ ✅
    gpt-5.3-codex Responses only ✅ ✅ ✅
    gemma4 on Ollama local OpenAI-compatible ✅ ✅ ✅

    Before, on gpt-5.5: every run failed while manage_people was offered; with only the artifact tools, the model sent content: {} and value: {}.

  • In the app, with main's server and the image built from this branch (crewai 1.15.41): artifact_create made a sheet (v1, South 200), then artifact_patch changed one cell (v2, South 275, note "Updated South revenue"). The audit trail has artifact.created and then artifact.edited with "via": "patch", both by the CrewAI Bot.

  • In the app, earlier, with the image built from this branch: plain reply, a choice card handed back and continued, a server-run computer command, a Firecrawl MCP call, and later turns answered from those results; the thread stored and reloaded whole.

  • Not run live: Anthropic and Gemini (no keys here). Their schema handling is covered by unit tests on CrewAI's own Anthropic and Gemini clients. The Model lock workflow is skipped for a fork's pull request.

lorenzejay and others added 7 commits November 26, 2026 16:53
The CrewAI engine was a one-step Flow that called the model through LiteLLM directly, so no
CrewAI Agent ever ran. It now runs CrewAI 1.15.45's conversational Agent session, served by
ag-ui-crewai with conversational=True, and keeps OpenBot's contract:

- The server's system messages (the Bot's role and tool guidance), which ag-ui-crewai's
  conversational mode drops, reach the Agent after CrewAI's own system prompt.
- OpenBot's tools are handed back to the server: each is a result_as_answer stand-in that ends
  the turn with the model's own call id, and its phantom backend tool events are suppressed.
- Messages keep the ids they arrived with, so the authoritative snapshot doesn't show the
  thread twice.
- An image on the request survives a continuation run.

Same harness id, image, port and route; no API change. OpenAI, Anthropic and Google models go
through CrewAI's native SDK clients (extras added); LiteLLM stays the fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A live run appends the current user message to the session as a plain dict, and CrewAI appends
its base ConversationMessage. Pydantic never sees in-place appends, and CrewAI serializes the
state on every step, so every run logged "serialized value may not be as expected". The
state's serializer now coerces those entries, leaving the list itself untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ol calls

CrewAI's Gemini client failed every run that followed an OpenBot tool, and
dropped images:

- A tool result now carries the name of the tool it answers, taken from the
  matching tool call; Gemini refuses an empty function_response name.
- Image parts become Gemini's inlineData / fileData parts, the only image
  parts CrewAI's Gemini client reads.
- A replayed tool call carries Google's documented placeholder thought
  signature, since AG-UI has nowhere to keep the real one between runs.

All three apply to Google only: a strict OpenAI-compatible server refuses a
name on a tool message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CrewAI Bot's main.py takes this branch's side; the next commit carries main's Gemini thought
signatures (CopilotKit#2397), progress reminders (CopilotKit#2436, CopilotKit#2443) and empty-turn rule (CopilotKit#2449) into it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ain's Gemini and reminder rules

The conversational Agent now does what the Bot on main did:

- A tool whose name CrewAI changes for the model (`showNote`, `askApproval`, `mcp__...`) is handed
  back under the server's name. The model calls it by `sanitize_tool_name`, and the hand-back
  looked it up by the server's name, so the turn answered "Handed to the caller to run."
- A handed-back call leaves out the `null`s its own schema did not ask for. CrewAI offers tools in
  strict mode, so every optional field came back as `null`.
- A `developer` message is kept as an instruction and left out of CrewAI's session, whose messages
  have no such role. It refused the whole run.
- An empty `OPENAI_BASE_URL` or `ANTHROPIC_BASE_URL` is unset. The providers' own SDKs took `""` as
  the address, and every OpenAI run failed with `APIConnectionError`.
- The model runs on CrewAI's own client for OpenAI, Anthropic and Google, whatever it is called.
  CrewAI sent a model it has not heard of (Gemini on the model gateway, `qwen/qwen3-8b`) to
  LiteLLM, which offered it no tools.
- The words the model said in a step that called tools are the reply's content. CrewAI keeps that
  step with none, so a line on a long job never reached the person.

From main: Gemini's thought signature goes out on the handed-back call's `encryptedValue` and back
to Gemini, with Google's placeholder only for a call the thread has none for (CopilotKit#2397); the progress
reminder after five silent steps (CopilotKit#2436, CopilotKit#2443), added to the latest result where CrewAI would take
a note in the person's turn for the request; the empty-turn rule (CopilotKit#2449); `google` as `gemini/`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CHANGELOG takes main's notes for 1.2.6 and adds the CrewAI Bot's entry under Bots.

@davidmckayv davidmckayv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this, Lorenze. Making the built-in CrewAI Bot a real CrewAI conversational agent is the right direction. The design holds up: tool calls go back to OpenBot under their original names, instructions and history are kept, and it gives the built-in Bot nothing a connected AG-UI Bot can't have. The tests through the real endpoint are good. Three things block it, though.

Blockers

  1. Tools with open-ended arguments can only ever be sent {} (agent-crewai/src/main.py:616). CrewAI offers tools in strict mode, which closes every open-ended object. I ran artifact_create and artifact_patch through it with their real schemas. On both OpenAI and Anthropic, an artifact's content comes out as an object that allows no keys, and a patch's value can only be {} or null. The model is forced to follow that schema, so a CrewAI Bot can no longer write an artifact at all. App and MCP tools with free-form maps break the same way. Today's Bot sends the schemas through unchanged. Please keep open-ended objects open, or turn off strict mode for those tools, and add a test with an open-ended schema.

  2. One email-typed field fails every run (main.py:616, and nothing catches the error). When a tool marks a field format: email, CrewAI needs a package the image doesn't install, and the run ends in RUN_ERROR. OpenBot's own manage_people tool marks its email field this way, so this hits every Bot that holds it. App tools are cleaned of this on the server, but built-in tools are sent as they are. Tuple-style items arrays crash the same way. Please convert these schemas safely, or install the missing dependency, and add a test for both.

  3. CrewAI's private internals are used with no version pin (requirements.txt:34-35). Besides the two adapter patches (main.py:330, main.py:570), the Bot relies on five private CrewAI internals: _conversation_streaming_enabled, _emit_conversation_message_added, _assistant_reply_appended, _standalone_agent and _skip_auto_memory (main.py:968-1033). The requirements set only minimum versions, so the image takes whatever is current when it's built. The PR says 1.15.45, and a fresh install already gets 1.15.47. If one of those names changes, the Bot could post its reply twice, or start writing CrewAI memory, which defaults to OpenAI embeddings. Please pin exact versions so upgrades come through CI.

Smaller things (not blocking)

  • When the model calls a tool under a name that doesn't match, the person sees "Handed to the caller to run." as the reply (main.py:368, main.py:530).
  • When two tool names collide, the numbered name can pass 64 characters (main.py:602-606).
  • System messages from the middle of a thread are moved to the top (main.py:320).
  • The global httpx patch parses every request body as JSON.
  • CrewAI prints its Flow console panels on every run, which fills the logs.
  • docs/agent-frameworks.md:293 says "Start from that file", but that file imports OpenBot-only modules.

Before rollout, these need checking live:

  • an artifact create and patch on OpenAI and on Anthropic;
  • a Bot holding many app (Composio/MCP) tools;
  • a tool round trip on Anthropic, on Gemini through the gateway, and on a local OpenAI-compatible server;
  • a Responses-only model making a real tool call;
  • the image built, with the Model lock workflow run on Anthropic and Google (both were skipped on this head).

No API or database impact. Happy to re-review as soon as the three blockers are in.

…-crewai

Review on CopilotKit#2636:

- Tools are offered with the caller's own schema and strict mode off, as the Bot
  on main does. Strict mode closed every open-ended object, so an artifact's
  content and a patch's value could only be sent {}. Unsupported formats are
  left out and tuple-style items become one schema.
- No Pydantic model is built from a caller's schema, so a format: email field
  (manage_people) or tuple-style items no longer fails every run.
- crewai==1.15.47 and ag-ui-crewai==1.0.0, pinned; a test checks the private
  parts the Bot relies on are still there.
- A call CrewAI matched by its sanitized name is handed back, and a turn that
  ran a caller's tool never replies with the stand-in's text.
- Numbered tool names stay within 64 characters.
- System messages from the middle of a thread stay in place.
- The httpx hook reads a body only when the chosen model is a Gemini model
  that checks signatures.
- CrewAI's console panels are quiet; errors and the trace link still log.
- A Responses-only model (gpt-5.3-codex) moves to the Responses API with
  OpenAI's current 404 wording.
- docs: read main.py as a reference, not a file to start from.
@lorenzejay

Copy link
Copy Markdown
Author

Thanks David, all three blockers are fixed, and so are the smaller items.

Blockers

  1. Open-ended arguments. The caller's tools are now offered with their own schema and strict mode off, the way the Bot on main sends them. That holds on every client CrewAI uses: Chat Completions, the Responses API, Anthropic, Gemini and LiteLLM. Tools CrewAI owns keep strict mode. I reproduced the bug first. On gpt-5.5 with the real artifact_create and artifact_patch schemas, the model sent content: {} and value: {}. With the fix it sends content: {"markdown": …} and value: 42. Tests: test_a_callers_tools_are_offered_as_written_and_not_in_strict_mode covers each client, and the caller-schemas case runs through the real endpoint.
  2. format: email and tuple items. A caller's schema no longer goes through create_model_from_schema; the arguments model accepts anything, since the server checks the call. The offered schema leaves out any format other than a date or time, and turns tuple-style items into a single schema with the length kept. Before the fix, every run failed while manage_people was offered (RUN_ERROR, ImportError). The same tests cover this.
  3. Pins. crewai[anthropic,google-genai]==1.15.47 and ag-ui-crewai==1.0.0, which is what the image was tested with. test_the_parts_of_crewai_and_ag_ui_crewai_this_bot_relies_on_are_there checks each private name where CrewAI reads it, and the adapter patches too, so an upgrade fails in CI.

Smaller things

  • Name mismatch: a call CrewAI matched by its sanitized name is handed back. If a turn ran a caller's tool and nothing can be handed back, the run fails instead of replying "Handed to the caller to run.".
  • Numbered names go through sanitize_tool_name, so they stay within 64 characters.
  • Mid-thread system messages stay after the turn they followed.
  • The httpx hook reads a body only when the chosen model is a Gemini model that checks signatures.
  • CrewAI's panels are off (its Rich console is set to quiet). The trace link and errors still log.
  • The docs now point at main.py as a reference, and say it imports OpenBot's shared/ modules and needs pins.

Before-rollout checks, live with the real schemas, two turns each (call handed back, result sent, answer finished):

  • OpenAI gpt-5.5: artifact create ✅, patch ✅, manage_people ✅
  • Responses API: gpt-6-astra ✅✅✅ and the Responses-only gpt-5.3-codex ✅✅✅. The codex run turned up one more bug: CrewAI moves a model to the Responses API only for an older wording of OpenAI's 404, so every codex run failed. It's fixed here, with a test, and I'll fix the wording in CrewAI too.
  • Local OpenAI-compatible server, gemma4 on Ollama: ✅✅✅
  • Many app tools: in my local install the Bot holds dozens of tools: built-in, computer, and the Firecrawl MCP app's. A Firecrawl call went through end to end. A Bot with a large Composio set is still worth a run.
  • Not done: Anthropic, and Gemini through the gateway (no keys here), plus the Model lock workflow on those two. Their schema handling is covered by unit tests on CrewAI's own clients. Could someone with gateway keys run those, or run the workflow on this branch?

The branch also merges main, and CHANGELOG.md is back to main's copy. The note is now under ## Changelog in the description.

@davidmckayv davidmckayv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, Lorenze. Re-reviewed at 2013948. Two of the three blockers are fully resolved, and the third is nearly there.

Resolved

  1. Open-ended tool schemas. A caller's tools are now offered as written with strict: False, on Chat Completions, the Responses API, Anthropic and Gemini. test_a_callers_tools_are_offered_as_written_and_not_in_strict_mode and the caller-schemas loopback check an artifact's content and a patch's value stay open.
  2. format: email and tuple-style items. No Pydantic model is built from a caller's schema any more, formats are stripped and list items become one schema. manage_people and a tuple field are both covered.
  3. Private CrewAI internals. test_the_parts_of_crewai_and_ag_ui_crewai_this_bot_relies_on_are_there really works. I renamed each of the five internals in an installed CrewAI, one at a time, and the test failed every time. It passes again once they are restored. All 66 harness tests pass locally on the pinned versions.

Still open

  • agent-crewai/requirements.txt:13: crewai==1.15.47 came out on 2026-11-30, two days ago. We only pin a release once it is at least two weeks old. 1.15.41 (2026-11-12) is the newest that qualifies, and I ran the full harness suite on it: 66 of 66 pass. Please pin crewai[anthropic,google-genai]==1.15.41. ag-ui-crewai==1.0.0 (2026-10-09) is fine as is.
  • The branch needs main merged in again. It is missing #2814, which fixed the support-window check that fails on every PR without it.
  • No CI has run on this head yet. It is a fork PR, so the workflows are waiting for a maintainer to approve them. Once the two changes above are pushed, we'll approve the run, and I'll approve and queue the PR when it's green.

… old

It is the version shared/model-lock.json records for agent-crewai. The harness suite and the live
tool round trips pass on it as they did on 1.15.47.
@lorenzejay

Copy link
Copy Markdown
Author

Thanks David. Both are in.

Checked on the new head with crewai 1.15.41:

  • The harness suite as CI runs it (fresh venv, pip install of both requirements files): 66 passed.
  • Live, with the real artifact_create, artifact_patch and manage_people schemas, two turns each: all pass on gpt-5.5, gpt-6-astra, the Responses-only gpt-5.3-codex, and gemma4 on a local OpenAI-compatible server.
  • In the app, with main's server and the rebuilt image: the Bot created a sheet (v1), then patched one cell (v2). The audit trail has artifact.created and then artifact.edited with "via": "patch", both by the CrewAI Bot.

Could a maintainer approve the workflows so CI runs on this head? Anthropic and Gemini through the gateway are still the two I can't run live here.

I'll open a separate bump once a newer CrewAI release is two weeks old. 1.15.42 to 1.15.46 add fixes this Bot will want: a streamed delta kept when its chunk also carries usage (vLLM), tool names that start with a digit, and vision on Claude 5.

@lorenzejay

Copy link
Copy Markdown
Author

@davidmckayv ready for another review at a9f20e0: crewai==1.15.41 is pinned and main (with #2814) is merged in. Details and results are in the comment above. Could you or another maintainer approve the workflows so CI runs on this head?

This branch has not been deployed

No deployments
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.

2 participants