Skip to content

Commit 18a11fe

Browse files
authored
fix: remove MCP tools from CrewAI template, standardize API key env vars (#113)
1 parent 9a752a1 commit 18a11fe

4 files changed

Lines changed: 39 additions & 51 deletions

File tree

src/assets/python/crewai/base/main.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import os
21
from crewai import Agent, Crew, Task, Process
32
from crewai.tools import tool
43
from bedrock_agentcore.runtime import BedrockAgentCoreApp
54
from model.load import load_model
6-
from mcp_client.client import get_streamable_http_mcp_client
75

86
app = BedrockAgentCoreApp()
97
log = app.logger
@@ -24,34 +22,33 @@ def add_numbers(a: int, b: int) -> int:
2422
def invoke(payload, context):
2523
log.info("Invoking Agent.....")
2624

27-
with get_streamable_http_mcp_client() as mcp_tools:
28-
# Define the Agent with Tools
29-
agent = Agent(
30-
role="Question Answering Assistant",
31-
goal="Answer the users questions",
32-
backstory="Always eager to answer any questions",
33-
llm=load_model(),
34-
tools=tools + mcp_tools,
35-
)
36-
37-
# Define the Task
38-
task = Task(
39-
agent=agent,
40-
description="Answer the users question: {prompt}",
41-
expected_output="An answer to the users question",
42-
)
43-
44-
# Create the Crew
45-
crew = Crew(agents=[agent], tasks=[task], process=Process.sequential)
46-
47-
# Process the user prompt
48-
prompt = payload.get("prompt", "What can you help me with?")
49-
50-
# Run the crew
51-
result = crew.kickoff(inputs={"prompt": prompt})
52-
53-
# Return result
54-
return {"result": result.raw}
25+
# Define the Agent with Tools
26+
agent = Agent(
27+
role="Question Answering Assistant",
28+
goal="Answer the users questions",
29+
backstory="Always eager to answer any questions",
30+
llm=load_model(),
31+
tools=tools,
32+
)
33+
34+
# Define the Task
35+
task = Task(
36+
agent=agent,
37+
description="Answer the users question: {prompt}",
38+
expected_output="An answer to the users question",
39+
)
40+
41+
# Create the Crew
42+
crew = Crew(agents=[agent], tasks=[task], process=Process.sequential)
43+
44+
# Process the user prompt
45+
prompt = payload.get("prompt", "What can you help me with?")
46+
47+
# Run the crew
48+
result = crew.kickoff(inputs={"prompt": prompt})
49+
50+
# Return result
51+
return {"result": result.raw}
5552

5653

5754
if __name__ == "__main__":

src/assets/python/crewai/base/mcp_client/client.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/assets/python/crewai/base/model/load.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ def _get_api_key() -> str:
4242

4343
def load_model() -> LLM:
4444
"""Get authenticated Anthropic model client."""
45+
api_key = _get_api_key()
46+
# CrewAI requires ANTHROPIC_API_KEY env var (ignores api_key parameter)
47+
os.environ["ANTHROPIC_API_KEY"] = api_key
4548
return LLM(
4649
model="anthropic/claude-sonnet-4-5-20250929",
47-
api_key=_get_api_key(),
50+
api_key=api_key,
4851
max_tokens=4096
4952
)
5053
{{/if}}
@@ -80,9 +83,12 @@ def _get_api_key() -> str:
8083

8184
def load_model() -> LLM:
8285
"""Get authenticated OpenAI model client."""
86+
api_key = _get_api_key()
87+
# CrewAI requires OPENAI_API_KEY env var (ignores api_key parameter)
88+
os.environ["OPENAI_API_KEY"] = api_key
8389
return LLM(
8490
model="openai/gpt-4o",
85-
api_key=_get_api_key()
91+
api_key=api_key
8692
)
8793
{{/if}}
8894
{{#if (eq modelProvider "Gemini")}}
@@ -117,8 +123,11 @@ def _get_api_key() -> str:
117123

118124
def load_model() -> LLM:
119125
"""Get authenticated Gemini model client."""
126+
api_key = _get_api_key()
127+
# CrewAI requires GEMINI_API_KEY env var (ignores api_key parameter)
128+
os.environ["GEMINI_API_KEY"] = api_key
120129
return LLM(
121130
model="gemini/gemini-2.0-flash",
122-
api_key=_get_api_key()
131+
api_key=api_key
123132
)
124133
{{/if}}

src/assets/python/crewai/base/pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ requires-python = ">=3.10"
1111
dependencies = [
1212
"opentelemetry-distro",
1313
"opentelemetry-exporter-otlp",
14-
"crewai-tools[mcp] >= 1.3.0",
15-
"mcp >= 1.20.0",
1614
"bedrock-agentcore >= 1.0.3",
1715
"botocore[crt] >= 1.35.0",
1816
"python-dotenv >= 1.0.1",

0 commit comments

Comments
 (0)