mirror of
https://github.com/google-gemini/gemini-fullstack-langgraph-quickstart.git
synced 2025-08-08 00:41:45 +03:00
Merge pull request #1 from nisaharan/Research_agent/cli_research
Add CLI example for agent
This commit is contained in:
12
README.md
12
README.md
@@ -73,6 +73,18 @@ The core of the backend is a LangGraph agent defined in `backend/src/agent/graph
|
||||
4. **Iterative Refinement:** If gaps are found or the information is insufficient, it generates follow-up queries and repeats the web research and reflection steps (up to a configured maximum number of loops).
|
||||
5. **Finalize Answer:** Once the research is deemed sufficient, the agent synthesizes the gathered information into a coherent answer, including citations from the web sources, using a Gemini model.
|
||||
|
||||
## CLI Example
|
||||
|
||||
For quick one-off questions you can execute the agent from the command line. The
|
||||
script `backend/examples/cli_research.py` runs the LangGraph agent and prints the
|
||||
final answer:
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
python examples/cli_research.py "What are the latest trends in renewable energy?"
|
||||
```
|
||||
|
||||
|
||||
## Deployment
|
||||
|
||||
In production, the backend server serves the optimized static frontend build. LangGraph requires a Redis instance and a Postgres database. Redis is used as a pub-sub broker to enable streaming real time output from background runs. Postgres is used to store assistants, threads, runs, persist thread state and long term memory, and to manage the state of the background task queue with 'exactly once' semantics. For more details on how to deploy the backend server, take a look at the [LangGraph Documentation](https://langchain-ai.github.io/langgraph/concepts/deployment_options/). Below is an example of how to build a Docker image that includes the optimized frontend build and the backend server and run it via `docker-compose`.
|
||||
|
||||
43
backend/examples/cli_research.py
Normal file
43
backend/examples/cli_research.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import argparse
|
||||
from langchain_core.messages import HumanMessage
|
||||
from agent.graph import graph
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Run the research agent from the command line."""
|
||||
parser = argparse.ArgumentParser(description="Run the LangGraph research agent")
|
||||
parser.add_argument("question", help="Research question")
|
||||
parser.add_argument(
|
||||
"--initial-queries",
|
||||
type=int,
|
||||
default=3,
|
||||
help="Number of initial search queries",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max-loops",
|
||||
type=int,
|
||||
default=2,
|
||||
help="Maximum number of research loops",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--reasoning-model",
|
||||
default="gemini-2.5-pro-preview-05-06",
|
||||
help="Model for the final answer",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
state = {
|
||||
"messages": [HumanMessage(content=args.question)],
|
||||
"initial_search_query_count": args.initial_queries,
|
||||
"max_research_loops": args.max_loops,
|
||||
"reasoning_model": args.reasoning_model,
|
||||
}
|
||||
|
||||
result = graph.invoke(state)
|
||||
messages = result.get("messages", [])
|
||||
if messages:
|
||||
print(messages[-1].content)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user