Advanced AI reasoning with Deepseek integration for complex queries and strategic analysis
Reasoning Mode combines Deepseek’s advanced reasoning capabilities with Gemini’s search tools to provide transparent, strategic analysis of complex queries.
// GET /api/reasoning?q=your_query&language=Englishconst response = await deepseek.chat.completions.create({ model: REASON_MODEL || "deepseek-reasoner", messages: [ { role: "system", content: `You are a helpful reasoner, acting as the **initial explorer** for a Search Agent. Your role is to **define the search strategy**, not to find the answer itself.` }, { role: "user", content: `The user query is: ${query}. Please provide your search strategy and explanation plan. Your answer should start with <think> and end with </think>` } ], stream: true // Real-time streaming});
// POST /api/search with reasoning contextconst searchPrompt = `Following reasoning analysis:${reasoning}to search and answer Query: ${query}`;const result = await chat.sendMessage(searchPrompt);
The Deepseek model receives specific instructions to act as a “search strategist”:
You are a helpful reasoner, acting as the **initial explorer** for a Search Agent.Your role is to **define the search strategy**, not to find the answer itself.Your task is to think like a search expert and determine:1. **Information Needs:** What specific types of information, facts, or data are absolutely necessary to fully understand and answer the user's query? Think about the *categories* of information we need to search for.2. **Explanation Strategy:** Once we have all the necessary information, how should we structure our explanation to clearly and comprehensively answer the user's query? Outline the *key points* or *logical steps* of the explanation.Remember, your output should be a **search and explanation plan**, not theanswer. Focus on *how* we will search and *how* we will explain, rather than*what* the answer is.
The reasoning model is explicitly instructed NOT to answer the query directly, only to plan the search strategy.
How would implementing universal basic income affect the economy?
<think>This query requires a multi-faceted analysis. Let me break down the searchstrategy:## Information Needs:1. **Definition & Models**: What is UBI? What are the different UBI models proposed (full vs partial, conditional vs unconditional)?2. **Economic Theory**: - Labor market effects (work incentives, labor supply) - Inflation concerns (demand-pull inflation from increased purchasing power) - Funding mechanisms (taxation, government spending reallocation)3. **Empirical Evidence**: - Pilot programs (Finland, Kenya, Stockton CA) - Historical experiments (Alaska Permanent Fund) - Research findings and outcomes4. **Stakeholder Perspectives**: - Economist viewpoints (pro and con) - Business community concerns - Social welfare advocates## Search Strategy:Perform searches on:1. "universal basic income economic impact research"2. "UBI pilot programs results Finland Kenya Stockton"3. "UBI inflation concerns economic theory"4. "UBI labor market effects work incentives"5. "UBI funding mechanisms taxation models"6. "economists debate universal basic income"7. "Alaska permanent fund dividend economic effects"8. "UBI pros and cons comprehensive analysis"## Explanation Structure:1. **Introduction**: Define UBI and its core principles2. **Theoretical Economic Effects**: - Labor supply and demand - Inflation and pricing - GDP and growth implications3. **Empirical Evidence**: Review pilot program outcomes4. **Implementation Challenges**: Funding, transition, political feasibility5. **Balanced Conclusion**: Summarize potential benefits and risks</think>
Gemini receives:
Following reasoning analysis:[Reasoning output from previous tab]to search and answer Query: How would implementing universal basic incomeaffect the economy?
Gemini then:
Performs the 8+ searches identified in the strategy
Synthesizes findings according to the explanation structure
Includes relevant sources and citations
Generates related questions
Adds contextual images if applicable
The user receives:Reasoning Process (visible during execution):
{ "sessionId": "abc123", "summary": "<formatted HTML response>", "sources": [ { "title": "Universal Basic Income Study Results", "url": "https://example.com/ubi-study", "snippet": "Research findings show..." } ], "relatedQuestions": [ "What are the main criticisms of UBI?", "Which countries have implemented UBI pilots?", "How would UBI affect inflation rates?" ], "images": [ { "url": "https://commons.wikimedia.org/...", "caption": "UBI pilot program in Finland", "alt": "Graph showing UBI pilot results" } ]}
# .env configurationREASON_MODEL=deepseek-reasoner # or any compatible modelREASON_MODEL_API_URL=https://api.deepseek.com/v1REASON_MODEL_API_KEY=your_api_key
The reasoning model must support OpenAI-compatible API and streaming responses.