-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathagent.py
More file actions
90 lines (74 loc) · 3.5 KB
/
Copy pathagent.py
File metadata and controls
90 lines (74 loc) · 3.5 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import asyncio
import logging
import secrets
from textwrap import dedent
from temporal.agent import Agent, Runner, Session, AgentConsole
from .tools import get_repos, search_github_code, download_github_file
from .sys_prompt import get_system_prompt
from .schemas import RepositorySchema, CodeSearchSchema, FileDownloadSchema
async def main():
"""Main interactive loop with GitHub-enabled agent."""
repository_agent = Agent(
name="Repository Explorer",
model_name="models/gemini-2.5-pro-preview-05-06",
instruction="""
You help find and explore GitHub repositories in organizations.
Use get_repos to retrieve repositories from specific organizations or users.
Focus on discovering relevant repositories that likely contain the implementation
or feature being asked about.
""",
functions=[get_repos],
input_schema=RepositorySchema
)
code_search_agent = Agent(
name="Code Search Specialist",
model_name="models/gemini-2.5-pro-preview-05-06",
instruction="""
You specialize in searching GitHub code to find specific implementations, functions, classes, and patterns.
Use targeted searches to locate exact code that answers technical questions.
Focus on finding the most relevant code snippets that directly address the user's query.
""",
functions=[search_github_code],
input_schema=CodeSearchSchema
)
file_download_agent = Agent(
name="Source Code Analyst",
model_name="models/gemini-2.5-pro-preview-05-06",
instruction="""
You specialize in downloading and analyzing specific source code files from GitHub repositories.
Use this when you need to examine the complete implementation of a specific file, function,
or module that was identified through code search.
Provide detailed analysis of code structure, patterns, and implementation details.
""",
functions=[download_github_file],
input_schema=FileDownloadSchema
)
root_agent = Agent(
name="GitHub Research Agent",
model_name="models/gemini-2.5-pro-preview-05-06",
instruction=get_system_prompt(),
sub_agents=[repository_agent, code_search_agent, file_download_agent]
)
message = """
🤖 GitHub Research Agent started!
I can help you research technical implementations and code patterns in GitHub repositories.
Example questions you can ask:
• How does Temporal implement rate limiting on the server side?
• How does Temporal's Go SDK implement workflow sleep?
• How does Temporal implement workflow state persistence and event sourcing?
• How does Temporal's worker polling mechanism work across different SDKs?
• How does Temporal implement workflow determinism and replay safety?
Note: Set GITHUB_TOKEN environment variable for higher API rate limits.
Type 'exit' to quit.
Send your first question:
"""
async with Runner(app_name="github_research_agent", agent=root_agent) as runner:
async with Session(client=runner.client, agent=root_agent) as session:
await AgentConsole(session=session).run(welcome_message=dedent(message))
if __name__ == "__main__":
try:
logging.basicConfig(level=os.environ.get("LOG_LEVEL", "INFO").upper())
asyncio.run(main())
except KeyboardInterrupt:
print("\n👋 Goodbye!")