alexliap commited on
Commit
6377a34
·
unverified ·
1 Parent(s): b859578

1st commit

Browse files
Files changed (7) hide show
  1. .gitignore +12 -0
  2. .pre-commit-config.yaml +23 -0
  3. .python-version +1 -0
  4. agent.py +27 -0
  5. app.py +62 -0
  6. pyproject.toml +18 -0
  7. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+ *.lock
12
+ .env
.pre-commit-config.yaml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.5.0
4
+ hooks:
5
+ - id: check-case-conflict
6
+ - id: check-merge-conflict
7
+ - id: check-symlinks
8
+ - id: check-yaml
9
+ - id: debug-statements
10
+ - id: end-of-file-fixer
11
+ - id: mixed-line-ending
12
+ - id: requirements-txt-fixer
13
+ - id: trailing-whitespace
14
+
15
+ - repo: https://github.com/astral-sh/ruff-pre-commit
16
+ rev: v0.4.1
17
+ hooks:
18
+ # Run the linter.
19
+ - id: ruff
20
+ args: [ --fix, "--ignore", "F821,F401,F811"]
21
+ # Run the formatter.
22
+ - id: ruff-format
23
+ types_or: [python, jupyter]
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.12
agent.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logfire
2
+ from deep_research_agent.nodes import (
3
+ BeginResearch,
4
+ FinalReport,
5
+ Researcher,
6
+ Supervisor,
7
+ WriteResearchBrief,
8
+ )
9
+ from deep_research_agent.state import ResearchState
10
+ from pydantic_graph import Graph
11
+
12
+ logfire.configure()
13
+ logfire.instrument_pydantic_ai()
14
+
15
+
16
+ async def query_agent(research_query: str):
17
+ state = ResearchState()
18
+ graph = Graph(
19
+ nodes=(BeginResearch, WriteResearchBrief, Supervisor, Researcher, FinalReport)
20
+ )
21
+
22
+ result = await graph.run(
23
+ start_node=BeginResearch(query=research_query),
24
+ state=state,
25
+ )
26
+
27
+ return result.output
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import asyncio
3
+ from agent import query_agent
4
+
5
+
6
+ # Simulate your async agent interaction
7
+ async def interact_with_agent(prompt: str):
8
+ # # This is where you'd call your real query_agent()
9
+ # await asyncio.sleep(1)
10
+ # urls = [
11
+ # "https://arxiv.org/abs/1234.5678",
12
+ # "https://openai.com/research",
13
+ # "https://example.com/article",
14
+ # ]
15
+ # report = f"Report generated for: '{prompt}'"
16
+ final_report = await query_agent(research_query=prompt)
17
+ final_report, refs = (
18
+ final_report.split("\n\n## References:\n\n")[0],
19
+ final_report.split("\n\n## References:\n\n")[1],
20
+ )
21
+ return final_report, refs
22
+
23
+
24
+ # Display URLs in Markdown
25
+ def format_urls(urls):
26
+ if not urls:
27
+ return "(No sources yet)"
28
+ return urls
29
+
30
+
31
+ with gr.Blocks(title="Deep Research Agent") as chat_app:
32
+ gr.Markdown("## 🧠 Deep Research Agent")
33
+
34
+ with gr.Row():
35
+ # Main chat area
36
+ with gr.Column(scale=4):
37
+ chatbot = gr.Chatbot(type="messages", label="Chat", height=550)
38
+ msg = gr.Textbox(placeholder="Ask a research question...")
39
+ clear = gr.ClearButton([msg, chatbot])
40
+
41
+ # Sidebar for URLs
42
+ with gr.Column(scale=1):
43
+ gr.Markdown("### 🔗 References")
44
+ url_display = gr.Markdown("(No sources yet)")
45
+
46
+ # Step 1: show user message immediately
47
+ def show_user_msg(message, chat_history: list):
48
+ chat_history.append({"role": "user", "content": message})
49
+ return chat_history
50
+
51
+ # Step 2: respond asynchronously (simulate the agent)
52
+ async def respond(message: str, chat_history: list):
53
+ report, urls = await interact_with_agent(message)
54
+ chat_history.append({"role": "assistant", "content": report})
55
+ return "", chat_history, format_urls(urls)
56
+
57
+ # Chain both: show user → respond with URLs
58
+ msg.submit(show_user_msg, [msg, chatbot], [chatbot], queue=False).then(
59
+ respond, [msg, chatbot], [msg, chatbot, url_display]
60
+ )
61
+
62
+ chat_app.launch()
pyproject.toml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "dra-app"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = [
8
+ "gradio>=5.49.1",
9
+ "pydantic-deep-research-agent",
10
+ ]
11
+
12
+ [dependency-groups]
13
+ dev = [
14
+ "pre-commit>=4.3.0",
15
+ ]
16
+
17
+ [tool.uv.sources]
18
+ pydantic-deep-research-agent = { git = "https://github.com/alexliap/pydantic_deep_research_agent" }
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio>=5.49.1
2
+ pydantic-deep-research-agent @ git+https://github.com/alexliap/pydantic_deep_research_agent