sse -> streamable + litellm package

pull/1080/head
Aksh Parekh 4 weeks ago
commit 449fe046e0

@ -3,13 +3,13 @@ from swarms.schemas.mcp_schemas import MCPConnection
mcp_config = MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
# headers={"Authorization": "Bearer 1234567890"},
timeout=5,
)
mcp_url = "http://0.0.0.0:8000/sse"
mcp_url = "http://0.0.0.0:8000/mcp"
# Initialize the agent
agent = Agent(

@ -39,8 +39,8 @@ agent = Agent(
dynamic_temperature_enabled=True,
output_type="all",
mcp_urls=[
"http://0.0.0.0:8000/sse",
"http://0.0.0.0:8001/sse",
"http://0.0.0.0:8000/mcp",
"http://0.0.0.0:8001/mcp",
],
)

@ -40,7 +40,7 @@ agent = Agent(
max_loops=2,
tools_list_dictionary=tools,
output_type="final",
mcp_url="http://0.0.0.0:8000/sse",
mcp_url="http://0.0.0.0:8000/mcp",
)
out = agent.run(

@ -21,25 +21,25 @@ def example_sync_execution():
# Example server URLs (replace with your actual MCP server URLs)
urls = [
"http://localhost:8000/sse", # Server 1
"http://localhost:8001/sse", # Server 2
"http://localhost:8002/sse", # Server 3
"http://localhost:8000/mcp", # Server 1
"http://localhost:8001/mcp", # Server 2
"http://localhost:8002/mcp", # Server 3
]
# Optional: Create connection objects for each server
connections = [
MCPConnection(
url="http://localhost:8000/sse",
url="http://localhost:8000/mcp",
authorization_token="token1", # if needed
timeout=10,
),
MCPConnection(
url="http://localhost:8001/sse",
url="http://localhost:8001/mcp",
authorization_token="token2", # if needed
timeout=10,
),
MCPConnection(
url="http://localhost:8002/sse",
url="http://localhost:8002/mcp",
authorization_token="token3", # if needed
timeout=10,
),
@ -111,9 +111,9 @@ async def example_async_execution():
# Example server URLs
urls = [
"http://localhost:8000/sse",
"http://localhost:8001/sse",
"http://localhost:8002/sse",
"http://localhost:8000/mcp",
"http://localhost:8001/mcp",
"http://localhost:8002/mcp",
]
# Example responses with multiple tool calls in a single response
@ -190,9 +190,9 @@ def example_get_tools_from_multiple_servers():
"""Example of getting tools from multiple servers."""
urls = [
"http://localhost:8000/sse",
"http://localhost:8001/sse",
"http://localhost:8002/sse",
"http://localhost:8000/mcp",
"http://localhost:8001/mcp",
"http://localhost:8002/mcp",
]
print("\n=== Getting Tools from Multiple Servers ===")

@ -13,7 +13,7 @@ async def create_agent_via_mcp():
# Connect to the MCP server using streamable HTTP
try:
async with http_client("http://localhost:8000/mcp") as (
async with http_client("http://localhost:8001/mcp") as (
read,
write,
_,

@ -7,10 +7,10 @@ import json
if __name__ == "__main__":
tools = get_mcp_tools_sync(
server_path="http://0.0.0.0:8000/sse",
server_path="http://0.0.0.0:8000/mcp",
format="openai",
connection=MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
headers={"Authorization": "Bearer 1234567890"},
timeout=10,
),

@ -13,12 +13,12 @@ response = {
}
connection = MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
headers={"Authorization": "Bearer 1234567890"},
timeout=10,
)
url = "http://0.0.0.0:8000/sse"
url = "http://0.0.0.0:8000/mcp"
if __name__ == "__main__":
tools = asyncio.run(

@ -7,10 +7,10 @@ from swarms.tools.mcp_client_tools import (
if __name__ == "__main__":
tools = get_mcp_tools_sync(
server_path="http://0.0.0.0:8000/sse",
server_path="http://0.0.0.0:8001/mcp",
format="openai",
connection=MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8001/mcp",
headers={"Authorization": "Bearer 1234567890"},
timeout=10,
),

@ -5,12 +5,12 @@ from swarms.schemas.mcp_schemas import MCPConnection
mcp_config = MCPConnection(
url="http://0.0.0.0:8000/sse",
url="http://0.0.0.0:8000/mcp",
# headers={"Authorization": "Bearer 1234567890"},
timeout=5,
)
urls = ["http://0.0.0.0:8000/sse", "http://0.0.0.0:8001/sse"]
urls = ["http://0.0.0.0:8001/mcp", "http://0.0.0.0:8001/mcp"]
out = get_tools_for_multiple_mcp_servers(
urls=urls,

@ -3,24 +3,27 @@ from swarms.prompts.finance_agent_sys_prompt import (
FINANCIAL_AGENT_SYS_PROMPT,
)
# Initialize the agent
# Initialize the financial analysis agent with a system prompt and configuration.
agent = Agent(
agent_name="Financial-Analysis-Agent",
agent_description="Personal finance advisor agent",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
agent_name="Financial-Analysis-Agent", # Name of the agent
agent_description="Personal finance advisor agent", # Description of the agent's role
system_prompt=FINANCIAL_AGENT_SYS_PROMPT, # System prompt for financial tasks
max_loops=1,
mcp_urls=[
"http://0.0.0.0:8001/mcp",
"http://0.0.0.0:8000/mcp",
"http://0.0.0.0:8001/mcp", # URL for the OKX crypto price MCP server
"http://0.0.0.0:8000/mcp", # URL for the agent creation MCP server
],
model_name="gpt-4o-mini",
output_type="all",
)
# Create a markdown file with initial content
# Run the agent with a specific instruction to use the create_agent tool.
# The agent is asked to create a new agent specialized for accounting rules in crypto.
out = agent.run(
# Example alternative prompt:
# "Use the get_okx_crypto_price to get the price of solana just put the name of the coin",
"Use the create_agent tool that is specialized in creating agents"
"Use the create_agent tool that is specialized in creating agents and create an agent speecialized for accounting rules in crypto"
)
# Print the output from the agent's run method.
print(out)

@ -29,3 +29,4 @@ numpy
openai
schedule
uvloop
litellm
Loading…
Cancel
Save