Skip to content

Commit 1165457

Browse files
authored
Merge pull request #238 from supreme-gg-gg/docs/crewai
Add CrewAI BYO Agent docs
2 parents ac4c8cf + 5288625 commit 1165457

1 file changed

Lines changed: 257 additions & 0 deletions

File tree

  • src/app/docs/kagent/examples/crewai-byo
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
---
2+
title: "BYO CrewAI Agents"
3+
pageOrder: 1
4+
description: "Bring your own CrewAI agent to kagent"
5+
---
6+
7+
export const metadata = {
8+
title: "Bringing your own CrewAI agent to kagent",
9+
description: "Learn how to bring your own CrewAI agent to kagent",
10+
author: "kagent.dev",
11+
};
12+
13+
# Bringing your own CrewAI agent to kagent
14+
15+
Bring your own custom agents. This example uses [CrewAI](https://www.crewai.com/), but you can also try out the [ADK guide](/docs/kagent/examples/a2a-byo/) or [LangGraph guide](/docs/kagent/examples/langchain-byo/). Such frameworks give you more control over the agent behavior and are well-suited for complex workflows and integration with external systems and APIs.
16+
17+
Unlike declarative agents that are defined by kagent resources with components such as system instructions, models, and tools written inline, these BYO agents give you full control over agent logic. If you have your own agent, no need to decompose its functions into separate kagent resources. Kagent can invoke your agent directly through the A2A protocol.
18+
19+
## Prerequisites
20+
21+
Install kagent by following the [quick start](/docs/kagent/getting-started/quickstart) guide.
22+
23+
## Building a custom agent
24+
25+
The following example builds a research crew agent from the [kagent code repository](https://github.com/kagent-dev/kagent). The sample app is built with CrewAI framework and performs research tasks using web search capabilities. It uses OpenAI's GPT models as the underlying LLM provider and Serper for web search.
26+
27+
1. Clone the kagent code repository.
28+
29+
```bash
30+
git clone https://github.com/kagent-dev/kagent.git
31+
cd kagent
32+
```
33+
34+
2. Optional: If you do not have a Docker registry, you can use the `make helm-install` command to create one as part of installing kagent in your kind cluster.
35+
36+
3. Build the custom agent image and push it to your local Docker registry.
37+
38+
```bash
39+
cd python/samples/crewai/research-crew
40+
docker build . -t localhost:5001/research-crew:latest --push
41+
```
42+
43+
### Adapting your own CrewAI agent
44+
45+
A quickstart and detailed guide for adapting existing CrewAI crews and flows to work with KAgent is available in the [package's README](https://github.com/kagent-dev/kagent/tree/main/python/packages/kagent-crewai).
46+
This provides a simple way to setup A2A server, tracing, and session-aware memory and state persistence.
47+
48+
Two complete examples are available in the `python/samples/crewai/` directory:
49+
50+
- [**Crew Example**](https://github.com/kagent-dev/kagent/tree/main/python/samples/crewai/research-crew): A multi-agent crew for web research and analysis
51+
- [**Flow Example**](https://github.com/kagent-dev/kagent/tree/main/python/samples/crewai/poem_flow): A CrewAI flow that generates and continues poems
52+
53+
## Creating a BYO Agent resource
54+
55+
Now that you have your own custom agent image, you can create a BYO Agent resource for kagent to manage.
56+
You will need a Serper API Key that you can get for free [from their website](https://serper.dev). Serper is a Google Search API used by most CrewAI examples and tutorials, but you can also plug in your own tools.
57+
58+
1. Save the API keys for your LLM provider and web search service in environment variables.
59+
60+
```bash
61+
export OPENAI_API_KEY=your-openai-api-key-here
62+
export SERPER_API_KEY=your-serper-api-key-here
63+
```
64+
65+
2. Create secrets with the API keys.
66+
67+
```bash
68+
kubectl create secret generic kagent-openai -n kagent \
69+
--from-literal=OPENAI_API_KEY=$OPENAI_API_KEY \
70+
--dry-run=client -o yaml | kubectl apply -f -
71+
72+
kubectl create secret generic kagent-serper -n kagent \
73+
--from-literal=SERPER_API_KEY=$SERPER_API_KEY \
74+
--dry-run=client -o yaml | kubectl apply -f -
75+
```
76+
77+
3. Create a BYO Agent resource.
78+
79+
```yaml
80+
kubectl apply -f - <<EOF
81+
apiVersion: kagent.dev/v1alpha2
82+
kind: Agent
83+
metadata:
84+
name: research-crew
85+
namespace: kagent
86+
spec:
87+
description: A research crew with multiple specialized agents for web research and analysis.
88+
type: BYO
89+
byo:
90+
deployment:
91+
image: localhost:5001/research-crew:latest
92+
env:
93+
- name: OPENAI_API_KEY
94+
valueFrom:
95+
secretKeyRef:
96+
name: kagent-openai
97+
key: OPENAI_API_KEY
98+
- name: SERPER_API_KEY
99+
valueFrom:
100+
secretKeyRef:
101+
name: kagent-serper
102+
key: SERPER_API_KEY
103+
EOF
104+
```
105+
106+
## Testing the A2A endpoint
107+
108+
The A2A endpoint is exposed on the port `8083` of the kagent controller service.
109+
110+
1. Enable port-forwarding on the `kagent-controller` service.
111+
112+
> Note that you could also expose the A2A endpoint publicly by using a gateway.
113+
114+
```bash
115+
kubectl port-forward svc/kagent-controller 8083:8083 -n kagent
116+
```
117+
118+
2. To test that the agent is available and has an agent card, send a request to the `.well-known/agent.json` endpoint. Note the API endpoint follows the pattern `/api/a2a/{namespace}/{agent-name}/.well-known/agent.json`.
119+
120+
```bash
121+
curl localhost:8083/api/a2a/kagent/research-crew/.well-known/agent.json
122+
```
123+
124+
Example output: This JSON object describes the agent as per the [A2A protocol](https://a2a.guide/protocol/agent-card.html).
125+
126+
```json
127+
{
128+
"name": "research_crew",
129+
"description": "A research crew with multiple specialized agents for web research and analysis.",
130+
"url": "http://127.0.0.1:8083/api/a2a/kagent/research-crew/",
131+
"version": "",
132+
"capabilities": {
133+
"streaming": true,
134+
"pushNotifications": false,
135+
"stateTransitionHistory": true
136+
},
137+
"defaultInputModes": ["text"],
138+
"defaultOutputModes": ["text"],
139+
"skills": []
140+
}
141+
```
142+
143+
## Invoking the agent
144+
145+
You can invoke the agent in several ways, including the kagent dashboard, kagent CLI, and the A2A host CLI.
146+
147+
### Dashboard
148+
149+
Launch the dashboard with `kagent dashboard`, find your `research-crew`, and start chatting. For complete steps, see the [Your First Agent](/docs/kagent/getting-started/first-agent) guide.
150+
151+
### kagent CLI
152+
153+
To use the kagent CLI, make sure that the controller is still being port-forwarded.
154+
155+
Then, use the invoke command. For more options, run `kagent help invoke`.
156+
157+
```shell
158+
kagent invoke --agent research-crew --task "Research topics on AI reliability and provide a summary."
159+
```
160+
161+
Example output: The output includes both the response as well as the details of the response. The formatting is in JSON but can be quite long, depending on the call and the agent configuration.
162+
163+
```json
164+
{
165+
"artifacts": [
166+
{
167+
"artifactId": "2d44a62e-d079-4dae-8ee8-f8759add9ffe",
168+
"parts": [
169+
{
170+
"kind": "text",
171+
"text": "After researching AI reliability, I found that it encompasses aspects like robustness, safety, and trustworthiness..."
172+
}
173+
]
174+
}
175+
],
176+
...
177+
}
178+
```
179+
180+
### A2A host CLI
181+
182+
You can use the A2A host CLI to invoke the agent. This CLI is part of the [A2A samples repository](https://github.com/a2aproject/a2a-samples/tree/main/samples/python/hosts/cli).
183+
184+
1. Clone the A2A samples repository.
185+
186+
```bash
187+
git clone https://github.com/a2aproject/a2a-samples.git
188+
```
189+
190+
2. From the `a2a-samples/samples/python/hosts/cli` directory, point the CLI to the kagent endpoint.
191+
192+
```bash
193+
cd a2a-samples/samples/python/hosts/cli
194+
uv run . --agent http://127.0.0.1:8083/api/a2a/kagent/research-crew
195+
```
196+
197+
Example output: The CLI connects to the kagent, displays the agent card and prompts you for input.
198+
199+
```console
200+
======= Agent Card ========
201+
{"capabilities":{"pushNotifications":false,"stateTransitionHistory":true,"streaming":true},"defaultInputModes":["text"],"defaultOutputModes":["text"],"description":"A research crew with multiple specialized agents for web research and analysis.","name":"research_crew","protocolVersion":"0.2.6","skills":[],"url":"http://127.0.0.1:8083/api/a2a/kagent/research-crew/","version":""}
202+
========= starting a new task ========
203+
204+
What do you want to send to the agent? (:q or quit to exit):
205+
```
206+
207+
3. Send the task `"Research topics on AI reliability and provide a summary."` to the agent. You'll be also prompted to optionally attach a file to the request, but just hit enter to skip this step.
208+
209+
Example output: You get a stream of events that include the prompt and the agent's response, such as the following.
210+
211+
```json
212+
{
213+
"contextId": "157a0834df2c459d9cee45316ffbfb5b",
214+
"final": false,
215+
"kind": "status-update",
216+
"metadata": {
217+
"crewai_app_name": "kagent__NS__research_crew",
218+
"crewai_author": "research_agent",
219+
"crewai_invocation_id": "e-8619b200-2f0a-4257-bd6b-b08bd1b139fd",
220+
"crewai_session_id": "157a0834df2c459d9cee45316ffbfb5b",
221+
"crewai_usage_metadata": {
222+
"candidatesTokenCount": 150,
223+
"candidatesTokensDetails": [
224+
{
225+
"modality": "TEXT",
226+
"tokenCount": 150
227+
}
228+
],
229+
"promptTokenCount": 500,
230+
"promptTokensDetails": [
231+
{
232+
"modality": "TEXT",
233+
"tokenCount": 500
234+
}
235+
],
236+
"totalTokenCount": 650
237+
},
238+
"crewai_user_id": "admin@kagent.dev"
239+
},
240+
"status": {
241+
"message": {
242+
"kind": "message",
243+
"messageId": "dd05c3cd-2dc3-4efd-9791-d7124be6dd52",
244+
"parts": [
245+
{
246+
"kind": "text",
247+
"text": "After researching AI reliability, I found that it encompasses aspects like robustness, safety, and trustworthiness..."
248+
}
249+
],
250+
"role": "agent"
251+
},
252+
"state": "working",
253+
"timestamp": "2025-08-14T22:15:04.276358+00:00"
254+
},
255+
"taskId": "59d2b071-04e9-4fef-a0dd-e925dd13cceb"
256+
}
257+
```

0 commit comments

Comments
 (0)