Skip to content

Commit 748f22f

Browse files
committed
groq support included
1 parent 7dfaace commit 748f22f

10 files changed

Lines changed: 620 additions & 33 deletions

File tree

examples/mcp/anthropic-mcp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, MCP
2+
3+
search_agent = Agent(
4+
instructions="""You help book apartments on Airbnb.""",
5+
llm="anthropic/claude-3-7-sonnet-20250219",
6+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
7+
)
8+
9+
search_agent.start("MUST USE airbnb_search Tool to Search. Search for Apartments in Paris for 2 nights. 04/28 - 04/30 for 2 adults. All Your Preference")

examples/mcp/gemini-mcp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, MCP
2+
3+
search_agent = Agent(
4+
instructions="""You help book apartments on Airbnb.""",
5+
llm="gemini/gemini-2.5-pro-exp-03-25",
6+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
7+
)
8+
9+
search_agent.start("MUST USE airbnb_search Tool to Search. Search for Apartments in Paris for 2 nights. 04/28 - 04/30 for 2 adults. All Your Preference")

examples/mcp/groq-mcp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, MCP
2+
3+
search_agent = Agent(
4+
instructions="""You help book apartments on Airbnb.""",
5+
llm="groq/llama-3.3-70b-versatile",
6+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
7+
)
8+
9+
search_agent.start("MUST USE airbnb_search Tool to Search. Search for Apartments in Paris for 2 nights. 04/28 - 04/30 for 2 adults. All Your Preference")

examples/mcp/mistral-mcp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, MCP
2+
3+
search_agent = Agent(
4+
instructions="""You help book apartments on Airbnb.""",
5+
llm="mistral/mistral-large-latest",
6+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
7+
)
8+
9+
search_agent.start("MUST USE airbnb_search Tool to Search. Search for Apartments in Paris for 2 nights. 04/28 - 04/30 for 2 adults. All Your Preference")

examples/mcp/openai-mcp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, MCP
2+
3+
search_agent = Agent(
4+
instructions="""You help book apartments on Airbnb.""",
5+
llm="gpt-4o-mini",
6+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
7+
)
8+
9+
search_agent.start("I want to book an apartment in Paris for 2 nights. 03/28 - 03/30 for 2 adults")

src/praisonai-agents/groq-mcp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, MCP
2+
3+
search_agent = Agent(
4+
instructions="""You help book apartments on Airbnb.""",
5+
llm="groq/llama-3.2-90b-vision-preview",
6+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
7+
)
8+
9+
search_agent.start("MUST USE airbnb_search Tool to Search. Search for Apartments in Paris for 2 nights. 04/28 - 04/30 for 2 adults. All Your Preference")

src/praisonai-agents/openai-mcp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, MCP
2+
3+
search_agent = Agent(
4+
instructions="""You help book apartments on Airbnb.""",
5+
llm="openai/gpt-4o-mini",
6+
tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt")
7+
)
8+
9+
search_agent.start("I want to book an apartment in Paris for 2 nights. 03/28 - 03/30 for 2 adults")

src/praisonai-agents/praisonaiagents/llm/llm.py

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,37 @@ def get_response(
436436

437437
# Handle tool calls
438438
if tool_calls and execute_tool_fn:
439+
# Convert tool_calls to a serializable format for all providers
440+
serializable_tool_calls = []
441+
for tc in tool_calls:
442+
if isinstance(tc, dict):
443+
serializable_tool_calls.append(tc) # Already a dict
444+
else:
445+
# Convert object to dict
446+
serializable_tool_calls.append({
447+
"id": tc.id,
448+
"type": getattr(tc, 'type', "function"),
449+
"function": {
450+
"name": tc.function.name,
451+
"arguments": tc.function.arguments
452+
}
453+
})
439454
messages.append({
440455
"role": "assistant",
441456
"content": response_text,
442-
"tool_calls": tool_calls
457+
"tool_calls": serializable_tool_calls
443458
})
444459

445460
for tool_call in tool_calls:
446-
function_name = tool_call["function"]["name"]
447-
arguments = json.loads(tool_call["function"]["arguments"])
461+
# Handle both object and dict access patterns
462+
if isinstance(tool_call, dict):
463+
function_name = tool_call["function"]["name"]
464+
arguments = json.loads(tool_call["function"]["arguments"])
465+
tool_call_id = tool_call["id"]
466+
else:
467+
function_name = tool_call.function.name
468+
arguments = json.loads(tool_call.function.arguments)
469+
tool_call_id = tool_call.id
448470

449471
logging.debug(f"[TOOL_EXEC_DEBUG] About to execute tool {function_name} with args: {arguments}")
450472
tool_result = execute_tool_fn(function_name, arguments)
@@ -462,18 +484,11 @@ def get_response(
462484
logging.debug(f"[TOOL_EXEC_DEBUG] About to display tool call with message: {display_message}")
463485
display_tool_call(display_message, console=console)
464486

465-
messages.append({
466-
"role": "tool",
467-
"tool_call_id": tool_call["id"],
468-
"content": json.dumps(tool_result)
469-
})
470-
else:
471-
logging.debug("[TOOL_EXEC_DEBUG] Verbose mode off, not displaying tool call")
472-
messages.append({
473-
"role": "tool",
474-
"tool_call_id": tool_call["id"],
475-
"content": "Function returned an empty output"
476-
})
487+
messages.append({
488+
"role": "tool",
489+
"tool_call_id": tool_call_id,
490+
"content": json.dumps(tool_result) if tool_result is not None else "Function returned an empty output"
491+
})
477492

478493
# If reasoning_steps is True, do a single non-streaming call
479494
if reasoning_steps:
@@ -930,15 +945,37 @@ async def get_response_async(
930945
tool_calls = tool_response.choices[0].message.get("tool_calls")
931946

932947
if tool_calls:
948+
# Convert tool_calls to a serializable format for all providers
949+
serializable_tool_calls = []
950+
for tc in tool_calls:
951+
if isinstance(tc, dict):
952+
serializable_tool_calls.append(tc) # Already a dict
953+
else:
954+
# Convert object to dict
955+
serializable_tool_calls.append({
956+
"id": tc.id,
957+
"type": getattr(tc, 'type', "function"),
958+
"function": {
959+
"name": tc.function.name,
960+
"arguments": tc.function.arguments
961+
}
962+
})
933963
messages.append({
934964
"role": "assistant",
935965
"content": response_text,
936-
"tool_calls": tool_calls
966+
"tool_calls": serializable_tool_calls
937967
})
938968

939969
for tool_call in tool_calls:
940-
function_name = tool_call.function.name
941-
arguments = json.loads(tool_call.function.arguments)
970+
# Handle both object and dict access patterns
971+
if isinstance(tool_call, dict):
972+
function_name = tool_call["function"]["name"]
973+
arguments = json.loads(tool_call["function"]["arguments"])
974+
tool_call_id = tool_call["id"]
975+
else:
976+
function_name = tool_call.function.name
977+
arguments = json.loads(tool_call.function.arguments)
978+
tool_call_id = tool_call.id
942979

943980
tool_result = await execute_tool_fn(function_name, arguments)
944981

@@ -949,17 +986,11 @@ async def get_response_async(
949986
else:
950987
display_message += "Function returned no output"
951988
display_tool_call(display_message, console=console)
952-
messages.append({
953-
"role": "tool",
954-
"tool_call_id": tool_call.id,
955-
"content": json.dumps(tool_result)
956-
})
957-
else:
958-
messages.append({
959-
"role": "tool",
960-
"tool_call_id": tool_call.id,
961-
"content": "Function returned an empty output"
962-
})
989+
messages.append({
990+
"role": "tool",
991+
"tool_call_id": tool_call_id,
992+
"content": json.dumps(tool_result) if tool_result is not None else "Function returned an empty output"
993+
})
963994

964995
# Get response after tool calls
965996
response_text = ""

src/praisonai-agents/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "praisonaiagents"
7-
version = "0.0.68"
7+
version = "0.0.69"
88
description = "Praison AI agents for completing complex tasks with Self Reflection Agents"
99
authors = [
1010
{ name="Mervin Praison" }

0 commit comments

Comments
 (0)