dtka's picture
Adding Agent
e5caa62
raw
history blame contribute delete
948 Bytes
import requests
import gradio as gr
import yaml
def fetch_agent_yaml(space_url):
try:
res = requests.get(f"{space_url}/agent.yaml")
return yaml.safe_load(res.text)
except:
return None
def build_agent_tool(agent_info, endpoint_url):
def tool_func(input_text):
try:
resp = requests.post(f"{endpoint_url}/agent", json={"input": input_text}, timeout=10)
return resp.json().get("output", "No structured output.")
except Exception as e:
return f"Error: {str(e)}"
return gr.TextTool(
name=agent_info.get("name", "Unnamed Agent"),
description=agent_info.get("description", "No description."),
func=tool_func
)
def discover_agents_from_urls(agent_urls):
tools = []
for url in agent_urls:
metadata = fetch_agent_yaml(url)
if metadata:
tools.append(build_agent_tool(metadata, url))
return tools