Skip to content

Commit 331b9bd

Browse files
authored
Merge branch 'main' into feat/role-flag
2 parents 51f688d + 90a782a commit 331b9bd

File tree

3 files changed

+101
-48
lines changed

3 files changed

+101
-48
lines changed

cookbook/tools/mcp/gibsonai.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,40 @@
4343
from agno.tools.mcp import MCPTools
4444

4545

46-
async def run_gibsonai_agent(message: str) -> None:
46+
async def run_gibsonai_agent(message: str):
4747
"""Run the GibsonAI agent with the given message."""
48-
async with MCPTools(
48+
mcp_tools = MCPTools(
4949
"uvx --from gibson-cli@latest gibson mcp run",
5050
timeout_seconds=300, # Extended timeout for GibsonAI operations
51-
) as mcp_tools:
52-
agent = Agent(
53-
name="GibsonAIAgent",
54-
model=OpenAIChat(id="gpt-4o"),
55-
tools=[mcp_tools],
56-
description="Agent for managing database projects and schemas",
57-
instructions=dedent("""\
58-
You are a GibsonAI database assistant. Help users manage their database projects and schemas.
59-
60-
Your capabilities include:
61-
- Creating new GibsonAI projects
62-
- Managing database schemas (tables, columns, relationships)
63-
- Deploying schema changes to hosted databases
64-
- Querying database schemas and data
65-
- Providing insights about database structure and best practices
66-
"""),
67-
markdown=True,
68-
show_tool_calls=True,
69-
)
51+
)
52+
53+
# Connect to the MCP server
54+
await mcp_tools.connect()
55+
56+
agent = Agent(
57+
name="GibsonAIAgent",
58+
model=OpenAIChat(id="gpt-4o"),
59+
tools=[mcp_tools],
60+
description="Agent for managing database projects and schemas",
61+
instructions=dedent("""\
62+
You are a GibsonAI database assistant. Help users manage their database projects and schemas.
63+
64+
Your capabilities include:
65+
- Creating new GibsonAI projects
66+
- Managing database schemas (tables, columns, relationships)
67+
- Deploying schema changes to hosted databases
68+
- Querying database schemas and data
69+
- Providing insights about database structure and best practices
70+
"""),
71+
markdown=True,
72+
show_tool_calls=True,
73+
)
74+
75+
# Run the agent
76+
await agent.aprint_response(message, stream=True)
7077

71-
# Run the agent
72-
await agent.aprint_response(message, stream=True)
78+
# Close the MCP connection
79+
await mcp_tools.close()
7380

7481

7582
# Example usage

libs/agno/agno/tools/github.py

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -458,35 +458,71 @@ def create_issue(self, repo_name: str, title: str, body: Optional[str] = NotSet)
458458
logger.error(f"Error creating issue: {e}")
459459
return json.dumps({"error": str(e)})
460460

461-
def list_issues(self, repo_name: str, state: str = "open", limit: int = 20) -> str:
462-
"""List issues for a repository.
461+
def list_issues(self, repo_name: str, state: str = "open", page: int = 1, per_page: int = 20) -> str:
462+
"""List issues for a repository with pagination.
463463
464464
Args:
465465
repo_name (str): The full name of the repository (e.g., 'owner/repo').
466466
state (str, optional): The state of issues to list ('open', 'closed', 'all'). Defaults to 'open'.
467-
limit (int, optional): The maximum number of issues to return. Defaults to 20.
467+
page (int, optional): Page number of results to return, counting from 1. Defaults to 1.
468+
per_page (int, optional): Number of results per page. Defaults to 20.
468469
Returns:
469-
A JSON-formatted string containing a list of issues.
470+
A JSON-formatted string containing a list of issues with pagination metadata.
470471
"""
471-
log_debug(f"Listing issues for repository: {repo_name} with state: {state}")
472+
log_debug(f"Listing issues for repository: {repo_name} with state: {state}, page: {page}, per_page: {per_page}")
472473
try:
473474
repo = self.g.get_repo(repo_name)
475+
474476
issues = repo.get_issues(state=state)
477+
475478
# Filter out pull requests after fetching issues
476-
logger.info(f"Issues: {issues}")
477-
filtered_issues = [issue for issue in issues if not issue.pull_request]
479+
total_issues = 0
480+
all_issues = []
481+
for issue in issues:
482+
if not issue.pull_request:
483+
all_issues.append(issue)
484+
total_issues += 1
485+
486+
# Calculate pagination metadata
487+
total_pages = (total_issues + per_page - 1) // per_page
488+
489+
# Validate page number
490+
if page < 1:
491+
page = 1
492+
elif page > total_pages and total_pages > 0:
493+
page = total_pages
494+
495+
# Get the specified page of results
478496
issue_list = []
479-
for issue in filtered_issues[:limit]:
480-
issue_info = {
481-
"number": issue.number,
482-
"title": issue.title,
483-
"user": issue.user.login,
484-
"created_at": issue.created_at.isoformat(),
485-
"state": issue.state,
486-
"url": issue.html_url,
487-
}
488-
issue_list.append(issue_info)
489-
return json.dumps(issue_list, indent=2)
497+
page_start = (page - 1) * per_page
498+
page_end = page_start + per_page
499+
500+
for i in range(page_start, min(page_end, total_issues)):
501+
if i < len(all_issues):
502+
issue = all_issues[i]
503+
issue_info = {
504+
"number": issue.number,
505+
"title": issue.title,
506+
"user": issue.user.login,
507+
"created_at": issue.created_at.isoformat(),
508+
"state": issue.state,
509+
"url": issue.html_url,
510+
}
511+
issue_list.append(issue_info)
512+
513+
meta = {
514+
"current_page": page,
515+
"per_page": per_page,
516+
"total_items": total_issues,
517+
"total_pages": total_pages
518+
}
519+
520+
response = {
521+
"data": issue_list,
522+
"meta": meta
523+
}
524+
525+
return json.dumps(response, indent=2)
490526
except GithubException as e:
491527
logger.error(f"Error listing issues: {e}")
492528
return json.dumps({"error": str(e)})

libs/agno/tests/unit/tools/test_github.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,29 @@ def test_get_pull_request_with_details(mock_github):
170170
result = github_tools.list_issues("test-org/test-repo")
171171
result_data = json.loads(result)
172172

173-
assert len(result_data) == 2
174-
assert result_data[0]["number"] == 1
175-
assert result_data[0]["state"] == "open"
176-
assert result_data[1]["number"] == 2
177-
assert result_data[1]["state"] == "closed"
173+
assert "data" in result_data
174+
assert "meta" in result_data
175+
assert len(result_data["data"]) == 2
176+
assert result_data["data"][0]["number"] == 1
177+
assert result_data["data"][0]["state"] == "open"
178+
assert result_data["data"][1]["number"] == 2
179+
assert result_data["data"][1]["state"] == "closed"
180+
181+
# Check pagination metadata
182+
assert result_data["meta"]["current_page"] == 1
183+
assert result_data["meta"]["per_page"] == 20
184+
assert result_data["meta"]["total_items"] == 2
185+
assert result_data["meta"]["total_pages"] == 1
178186

179187
# Test listing only open issues
180188
mock_repo.get_issues.return_value = [mock_issue1]
181189
result = github_tools.list_issues("test-org/test-repo", state="open")
182190
result_data = json.loads(result)
183191

184-
assert len(result_data) == 1
185-
assert result_data[0]["state"] == "open"
192+
assert "data" in result_data
193+
assert len(result_data["data"]) == 1
194+
assert result_data["data"][0]["state"] == "open"
195+
assert result_data["meta"]["total_items"] == 1
186196

187197

188198
def test_create_issue(mock_github):

0 commit comments

Comments
 (0)