Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document-upload-ag-2793 #2325

Merged
merged 9 commits into from
Mar 12, 2025
10 changes: 6 additions & 4 deletions cookbook/examples/apps/github_mcp_agent/agents.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import os
from textwrap import dedent

from agno.agent import Agent
from agno.tools.mcp import MCPTools
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client


async def run_github_agent(message):
if not os.getenv("GITHUB_TOKEN"):
return "Error: GitHub token not provided"

try:
server_params = StdioServerParameters(
command="npx",
args=["-y", "@modelcontextprotocol/server-github"],
)

# Create client session
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# Initialize MCP toolkit
mcp_tools = MCPTools(session=session)
await mcp_tools.initialize()

# Create agent
agent = Agent(
tools=[mcp_tools],
Expand All @@ -36,7 +38,7 @@ async def run_github_agent(message):
markdown=True,
show_tool_calls=True,
)

# Run agent
response = await agent.arun(message)
return response.content
Expand Down
54 changes: 33 additions & 21 deletions cookbook/examples/apps/github_mcp_agent/app.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,58 @@
import asyncio
import os

import streamlit as st
from agents import run_github_agent

# Page config
st.set_page_config(page_title="🐙 GitHub MCP Agent", page_icon="🐙", layout="wide")

# Title and description
st.markdown("<h1 class='main-header'>🐙 GitHub MCP Agent</h1>", unsafe_allow_html=True)
st.markdown("Explore GitHub repositories with natural language using the Model Context Protocol")
st.markdown(
"Explore GitHub repositories with natural language using the Model Context Protocol"
)

# Setup sidebar for API key
with st.sidebar:
st.header("🔑 Authentication")
github_token = st.text_input("GitHub Token", type="password",
help="Create a token with repo scope at github.com/settings/tokens")

github_token = st.text_input(
"GitHub Token",
type="password",
help="Create a token with repo scope at github.com/settings/tokens",
)

if github_token:
os.environ["GITHUB_TOKEN"] = github_token

st.markdown("---")
st.markdown("### Example Queries")

st.markdown("**Issues**")
st.markdown("- Show me issues by label")
st.markdown("- What issues are being actively discussed?")

st.markdown("**Pull Requests**")
st.markdown("- What PRs need review?")
st.markdown("- Show me recent merged PRs")

st.markdown("**Repository**")
st.markdown("- Show repository health metrics")
st.markdown("- Show repository activity patterns")

st.markdown("---")
st.caption("Note: Always specify the repository in your query if not already selected in the main input.")
st.caption(
"Note: Always specify the repository in your query if not already selected in the main input."
)

# Query input
col1, col2 = st.columns([3, 1])
with col1:
repo = st.text_input("Repository", value="agno-agi/agno", help="Format: owner/repo")
with col2:
query_type = st.selectbox("Query Type", [
"Issues", "Pull Requests", "Repository Activity", "Custom"
])
query_type = st.selectbox(
"Query Type", ["Issues", "Pull Requests", "Repository Activity", "Custom"]
)

# Create predefined queries based on type
if query_type == "Issues":
Expand All @@ -55,8 +64,11 @@
else:
query_template = ""

query = st.text_area("Your Query", value=query_template,
placeholder="What would you like to know about this repository?")
query = st.text_area(
"Your Query",
value=query_template,
placeholder="What would you like to know about this repository?",
)

# Run button
if st.button("🚀 Run Query", type="primary", use_container_width=True):
Expand All @@ -71,15 +83,15 @@
full_query = f"{query} in {repo}"
else:
full_query = query

result = asyncio.run(run_github_agent(full_query))

# Display results in a nice container
st.markdown("### Results")
st.markdown(result)

# Display help text for first-time users
if 'result' not in locals():
if "result" not in locals():
st.markdown(
"""<div class='info-box'>
<h4>How to use this app:</h4>
Expand All @@ -96,10 +108,10 @@
<li>More specific queries yield better results</li>
<li>This app requires Node.js to be installed (for the npx command)</li>
</ul>
</div>""",
unsafe_allow_html=True
</div>""",
unsafe_allow_html=True,
)

# Footer
st.markdown("---")
st.write("Built with Streamlit, Agno, and Model Context Protocol ❤️")
st.write("Built with Streamlit, Agno, and Model Context Protocol ❤️")
25 changes: 25 additions & 0 deletions cookbook/models/anthropic/pdf_input_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pathlib import Path

from agno.agent import Agent
from agno.media import File
from agno.models.anthropic import Claude

# Please download the file using
# wget https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf

pdf_path = Path(__file__).parents[3].joinpath("ThaiRecipes.pdf")

agent = Agent(
model=Claude(id="claude-3-5-sonnet-20241022"),
markdown=True,
)

agent.print_response(
"Summarize the contents of the attached file.",
files=[
File(
filepath=pdf_path,
),
],
stream=True,
)
16 changes: 16 additions & 0 deletions cookbook/models/anthropic/pdf_input_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from agno.agent import Agent
from agno.media import File
from agno.models.anthropic import Claude

agent = Agent(
model=Claude(id="claude-3-5-sonnet-20241022"),
markdown=True,
)

agent.print_response(
"Summarize the contents of the attached file.",
files=[
File(url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"),
],
stream=True,
)
20 changes: 20 additions & 0 deletions cookbook/models/google/gemini/pdf_input_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pathlib import Path

from agno.agent import Agent
from agno.media import File
from agno.models.google import Gemini

# Please download the file using
# wget https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf

pdf_path = Path(__file__).parents[4].joinpath("ThaiRecipes.pdf")

agent = Agent(
model=Gemini(id="gemini-2.0-flash-exp"),
markdown=True,
)

agent.print_response(
"Summarize the contents of the attached file.",
files=[File(filepath=pdf_path)],
)
13 changes: 13 additions & 0 deletions cookbook/models/google/gemini/pdf_input_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from agno.agent import Agent
from agno.media import File
from agno.models.google import Gemini

agent = Agent(
model=Gemini(id="gemini-2.0-flash-exp"),
markdown=True,
)

agent.print_response(
"Summarize the contents of the attached file.",
files=[File(url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf")],
)
Loading