1- import os
21from crewai import Agent , Crew , Task , Process
32from crewai .tools import tool
43from bedrock_agentcore .runtime import BedrockAgentCoreApp
54from model .load import load_model
6- from mcp_client .client import get_streamable_http_mcp_client
75
86app = BedrockAgentCoreApp ()
97log = app .logger
@@ -24,34 +22,33 @@ def add_numbers(a: int, b: int) -> int:
2422def 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
5754if __name__ == "__main__" :
0 commit comments