File size: 945 Bytes
ba4f42c
 
2362138
ba4f42c
 
2362138
99ba107
c22b2c8
5de8172
c22b2c8
ba4f42c
 
2362138
ba4f42c
2362138
ba4f42c
2362138
ba4f42c
2362138
ba4f42c
 
 
2362138
ba4f42c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr

from smolagents import InferenceClientModel, CodeAgent
from smolagents.mcp_client import MCPClient

# Use a 'with' block to ensure proper disconnection
# Use 'with' for safe connection/disconnection
with MCPClient({
    "url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp",
    "transport": "streamable-http"}) as mcp_client: # Fetch the available tools from the remote MCP server
    tools = mcp_client.get_tools()

    # Set up the agent with tools and a default language model
    model = InferenceClientModel()
    agent = CodeAgent(tools=tools, model=model)

    # Launch Gradio interface
    demo = gr.ChatInterface(
        fn=lambda message, history: (str(agent.run(message)), history),
        type="messages",
        examples=["Prime factorization of 68"],
        title="Agent with MCP Tools",
        description="This is a simple agent that uses MCP tools to answer questions."
    )

    demo.launch()