This notebook is a minimal implementation of ReAct: Synergizing Reasoning and Acting in Language Models with the Google gemini-2.5-flash model. You’ll use ReAct prompting to configure a model to search Wikipedia to find the answer to a user’s question.
In this walkthrough, you will learn how to:
Set up your development environment and API access to use Gemini.
Use a ReAct few-shot prompt.
Use the newly prompted model for multi-turn conversations (chat).
Connect the model to the Wikipedia API.
Have conversations with the model (try asking it questions like “how tall is the Eiffel Tower?”) and watch it search Wikipedia.
You can create your API key using Google AI Studio with a single click.
Remember to treat your API key like a password. Don’t accidentally save it in a notebook or source file you later commit to GitHub. In this notebook we will be storing the API key in a .env file. You can also set it as an environment variable or use a secret manager.
Another option is to set the API key as an environment variable. You can do this in your terminal with the following command:
$ export GEMINI_API_KEY="<YOUR_API_KEY>"
Load the API key
To load the API key from the .env file, we will use the dotenv package. This package loads environment variables from a .env file into process.env.
$ npm install dotenv
Then, we can load the API key in our code:
const dotenv =require("dotenv") astypeofimport("dotenv");dotenv.config({ path:"../.env",});const GEMINI_API_KEY =process.env.GEMINI_API_KEY??"";if (!GEMINI_API_KEY) {thrownewError("GEMINI_API_KEY is not set in the environment variables");}console.log("GEMINI_API_KEY is set in the environment variables");
GEMINI_API_KEY is set in the environment variables
Note
In our particular case the .env is is one directory up from the notebook, hence we need to use ../ to go up one directory. If the .env file is in the same directory as the notebook, you can omit it altogether.
With the new SDK, now you only need to initialize a client with you API key (or OAuth if using Vertex AI). The model is now set in each call.
const google =require("@google/genai") astypeofimport("@google/genai");const ai =new google.GoogleGenAI({ apiKey: GEMINI_API_KEY });
Select a model
Now select the model you want to use in this guide, either by selecting one in the list or writing it down. Keep in mind that some models, like the 2.5 ones are thinking models and thus take slightly more time to respond (cf. thinking notebook for more details and in particular learn how to switch the thiking off).
Here, you will be working with the following ReAct prompt with a few minor adjustments.
Note
The prompt and in-context examples used here are borrowed from https://github.com/ysymyth/ReAct which is published under a MIT license.
const MODEL_INSTRUCTION =` Solve a question answering task with interleaving Thought, Action, Observation steps. Thought can reason about the current situation, Observation is understanding relevant information from an Action's output and Action can be of three types: (1) search, which searches the exact entity on Wikipedia and returns the first paragraph if it exists. If not, it will return some similar entities to search and you can try to search the information from those topics. (2) lookup, which returns the next sentence containing keyword in the current context. This only does exact matches, so keep your searches short. (3) finish, which returns the answer and finishes the task. </search/> : Perform a Wikipedia search via external API. Example: "<search>What is the capital of France?</search>". </lookup/> : Lookup for specific information on a page with the Wikipedia API. So say once you search and get a page, you can follow up with a lookup to get more information. Example: "<lookup>What is the capital of France?</lookup>". </finish/> : Stop the execution of the model and return the answer. Example: "<finish>The capital of France is Paris.</finish>". Make sure to use the </search/>, </lookup/> and </finish/> tags to indicate the type of action you want to perform and enclose the content of the action in the tags. If you want to search for a specific entity, use the </search/> tag. If you want to look up a specific piece of information, use the </lookup/> tag. If you want to finish the task and return the answer, use the </finish/> tag.`;
Few-shot prompting to enable in-context learning with Gemini
While large language models show good understanding of the instructions they are prompted with, they still may perform poorly on complex tasks in a zero-shot setting. Hence, you will now provide a few examples along with your prompt to steer the model’s output according to your needs. This in-context learning improves the model’s performance significantly.
const examples =`Here are some examples.Example 1Question:What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?Thought 1I need to search "Colorado orogeny" to find what area the eastern sector extends into.Action 1<search>Colorado orogeny</search>Observation 1The Colorado orogeny was an episode of mountain building (an orogeny) in Colorado and surrounding areas.Thought 2The article does not mention the eastern sector. I need to look up "eastern sector".Action 2<lookup>eastern sector</lookup>Observation 2The eastern sector extends into the High Plains and is called the Central Plains orogeny.Thought 3The eastern sector extends into the High Plains. I now need to search "High Plains (United States)" to find the elevation range.Action 3<search>High Plains (United States)</search>Observation 3The High Plains are a subregion of the Great Plains. From east to west, the High Plains rise in elevation from around 1,800 to 7,000 ft (550 to 2,130 m).Thought 4The elevation range is 1,800 to 7,000 ft.Action 4<finish>The elevation range is 1,800 to 7,000 ft.</finish>Example 2Question:Musician and satirist Allie Goertz wrote a song about the "The Simpsons" character Milhouse, who Matt Groening named after who?Thought 1I should search "Milhouse" to find out who he was named after.Action 1<search>Milhouse</search>Observation 1Milhouse Mussolini Van Houten is a recurring character in the Fox animated television series The Simpsons voiced by Pamela Hayden and created by Matt Groening.Thought 2The paragraph does not mention who Milhouse is named after. I will look up "named after".Action 2<lookup>named after</lookup>Observation 2Milhouse was named after U.S. president Richard Nixon, whose middle name was Milhous.Thought 3Milhouse was named after Richard Nixon.Action 3<finish>Milhouse was named after U.S. president Richard Nixon.</finish>Example 3Question:Which documentary is about Finnish rock groups, Adam Clayton Powell or The Saimaa Gesture?Thought 1Search "Adam Clayton Powell" to determine if it's about Finnish rock groups.Action 1<search>Adam Clayton Powell</search>Observation 1Could not find [Adam Clayton Powell]. Similar: ['Adam Clayton Powell III', 'Adam Clayton Powell Jr. State Office Building', 'Adam Clayton Powell (film)', etc.]Thought 2Try searching the documentary specifically: "Adam Clayton Powell (film)".Action 2<search>Adam Clayton Powell (film)</search>Observation 2Adam Clayton Powell is a 1989 American documentary film about the rise and fall of African-American politician Adam Clayton Powell Jr.Thought 3It is not about Finnish rock groups. Now search "The Saimaa Gesture".Action 3<search>The Saimaa Gesture</search>Observation 3The Saimaa Gesture is a 1981 Finnish documentary film about Finnish rock bands Eppu Normaali, Hassisen Kone, and Juice Leskinen Slam on tour.Thought 4The Saimaa Gesture is about Finnish rock groups.Action 4<finish>The Saimaa Gesture is the documentary about Finnish rock groups.</finish>Example 4Question:What profession do Nicholas Ray and Elia Kazan have in common?Thought 1Search "Nicholas Ray" and identify his professions.Action 1<search>Nicholas Ray</search>Observation 1Nicholas Ray was an American film director, screenwriter, and actor best known for the film Rebel Without a Cause.Thought 2Now search "Elia Kazan" to compare professions.Action 2<search>Elia Kazan</search>Observation 2Elia Kazan was a film and theatre director, producer, screenwriter, and actor.Thought 3Both were directors, screenwriters, and actors.Action 3<finish>Nicholas Ray and Elia Kazan were both directors, screenwriters, and actors.</finish>Example 5Question:Which magazine was started first, Arthur's Magazine or First for Women?Thought 1Search "Arthur's Magazine" to find the start year.Action 1<search>Arthur's Magazine</search>Observation 1Arthur's Magazine (1844–1846) was a literary periodical published in the 19th century.Thought 2Arthur's Magazine started in 1844. Now search "First for Women".Action 2<search>First for Women</search>Observation 2First for Women is a magazine published in the USA. It was started in 1989.Thought 3Arthur's Magazine (1844) was started earlier than First for Women (1989).Action 3<finish>Arthur's Magazine was started first.</finish>Example 6Question:Were Pavel Urysohn and Leonid Levin known for the same type of work?Thought 1Search "Pavel Urysohn" and find his field of work.Action 1<search>Pavel Urysohn</search>Observation 1Pavel Urysohn was a Soviet mathematician best known for contributions to dimension theory.Thought 2Now search "Leonid Levin" and compare.Action 2<search>Leonid Levin</search>Observation 2Leonid Levin is a Soviet-American mathematician and computer scientist.Thought 3Both were mathematicians, so yes—they were known for the same type of work.Action 3<finish>Yes, both Pavel Urysohn and Leonid Levin were known for work in mathematics.</finish>Question{question}`;
Copy the instructions along with examples in a file called model_instructions.txt
As instructed by the prompt, the model will be generating Thought-Action-Observation traces, where every Action trace could be one of the following tokens:
</search/> : Perform a Wikipedia search via external API.
</lookup/> : Lookup for specific information on a page with the Wikipedia API.
</finish/> : Stop the execution of the model and return the answer.
If the model encounters any of these tokens, the model should make use of the tools made available to the model. This understanding of the model to leverage acquired toolsets to collect information from the external world is often referred to as function calling. Therefore, the next goal is to imitate this function calling technique in order to allow ReAct prompted Gemini model to access the external groundtruth.
The Gemini API supports function calling and you could use this feature to set up your tools. However, for this tutorial, you will learn to simulate it using stop_sequences parameter.
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */const wikipedia =require("wikipedia") astypeofimport("wikipedia");asyncfunctionsearch(query:string):Promise<string> {let observation:string|null=null; query = query.trim();try {// try to get the summary for requested `query` from the Wikipediaconst summary =await wikipedia.summary(query);// @ts-expect-error invalid typesconst page =await wikipedia.page(summary.title);const wikiUrl = page.fullurl; observation =this.clean(summary.extract);// if successful, return the first 2-3 sentences from the summary as model's contextconst observationResponse =await ai.models.generateContent({ model: MODEL_ID, contents: observation, }); observation = observationResponse.text??"";// keep track of the model's search historythis._searchHistory.push(query);this._searchUrls.push(wikiUrl);console.log(`Information Source: ${wikiUrl}`); } catch (e) {// if the page is ambiguous/does not exist, return similar search phrases for model's context observation =`Could not find ["${query}"].`;// get a list of similar search topics// @ts-expect-error invalid typesconst searchResults =await wikipedia.search(query); observation +=` Similar: ${JSON.stringify(searchResults)}. You should search for one of those instead.`; }return observation;}
Lookup
Look for a specific phrase on the Wikipedia page.
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */asyncfunctionlookup(phrase:string, contextLength =1000):Promise<string> {// get the last searched Wikipedia page and find `phrase` in it.// @ts-expect-error invalid typesconst page =await wikipedia.page(this._searchHistory[this._searchHistory.length-1]);const cleanedPage =this.clean(await page.content()) asstring;const startIndex = cleanedPage.indexOf(phrase);// extract sentences considering the context length definedconst result = cleanedPage.substring(Math.max(0, startIndex - contextLength), startIndex + phrase.length+ contextLength );console.log(`Information Source: ${this._searchUrls[this._searchUrls.length-1]}`);return result;}
Finish
Instruct the pipline to terminate its execution.
/* eslint-disable @typescript-eslint/no-unsafe-member-access */functionfinish(_:unknown):void {// Instruct the pipline to terminate its execution.this._shouldContinue=false;console.log(`Information Sources: ${this._searchUrls}`);}
Setup
You will now build an end-to-end pipeline to facilitate multi-turn chat with the ReAct-prompted Gemini model.
/* eslint-disable @typescript-eslint/no-unnecessary-condition */import { Chat, GenerateContentConfig } from"@google/genai";@AddMethod("search", search)@AddMethod("lookup", lookup)@AddMethod("finish", finish)class ReActPipeline {private chat: Chat;private _reactPrompt:string;private _shouldContinue =true;private _searchHistory:string[] = [];private _searchUrls:string[] = [];constructor(modelId:string, prompt:string) {this.chat= ai.chats.create({ model: modelId, });if (fs.existsSync(prompt)) {this._reactPrompt= fs.readFileSync(prompt,"utf-8"); } else {this._reactPrompt= prompt; } }asyncquery(question:string, maxCalls =15, generateConfig: GenerateContentConfig = {}) {console.assert(maxCalls >0&& maxCalls <=15,"max_calls must be between 1 and 15");let modelPrompt =this.chat.getHistory().length===0?this._reactPrompt.replace("{question}", question) : question;// const callableEntities = ["", "", ""];this._shouldContinue=true;for (let i =0; i < maxCalls &&this._shouldContinue; i++) {const response =awaitthis.chat.sendMessage({ message: modelPrompt, config: {...generateConfig,// stopSequences: callableEntities, }, });const text = response.text??""; tslab.display.markdown(text);const chatHistory =this.chat.getHistory();const chatHistoryParts = chatHistory[chatHistory.length-1].parts;const lastPart = (chatHistoryParts[chatHistoryParts.length-1].text??"").trim();const match =/<([^>]+)>(.*)<\/\1>/.exec(lastPart);if (match) {const cmd = match[1].trim();const query = match[2].trim();console.log(`Command: ${cmd}, Query: ${query}`);const observation =awaitthis[cmd](query);if (!this._shouldContinue) {break; }const streamMessage =`\nObservation ${i +1}\n${observation}`;console.log(streamMessage); modelPrompt =`<${cmd}>${query}${cmd}'s Output: ${streamMessage}`; } else {console.warn("No valid command found in the response. Please ensure the model is generating valid thought-action-observation traces." ); modelPrompt ="Please try to generate thought-action-observation traces as instructed by the prompt."; }awaitnewPromise((resolve) =>setTimeout(resolve,5000));// wait for 1 second before the next iteration } }clean(text:string):string {return text.replace("\n"," "); }}
Test ReAct prompted Gemini model
const reactChat =newReActPipeline(MODEL_ID, MODEL_INSTRUCTIONS_FILE);await reactChat.query("What are the total of ages of the main trio from the new Percy Jackson and the Olympians TV series in real life?",15, { temperature:0.4 });
Thought 1 I need to find the ages of the main trio from the new Percy Jackson and the Olympians TV series in real life. I will start by searching for “Percy Jackson and the Olympians (TV series)”.
Action 1
<search>Percy Jackson and the Olympians (TV series)</search>
Command: search, Query: Percy Jackson and the Olympians (TV series)
Information Source: https://en.wikipedia.org/wiki/Percy_Jackson_and_the_Olympians_(TV_series)
Observation 1
This is a concise and accurate description of the Percy Jackson and the Olympians TV series. It covers the following key information:
* **Type of media:** American fantasy television series
* **Creators:** Rick Riordan and Jonathan E. Steinberg
* **Platform:** Disney+
* **Source Material:** Based on the book series by Rick Riordan
* **Main Cast:** Walker Scobell, Leah Sava Jeffries, and Aryan Simhadri
* **Main Character Roles:** Percy Jackson, Annabeth Chase, and Grover Underwood
It's a good, basic summary for someone who is unfamiliar with the series.
Thought 2 Now I know the names of the main trio: Walker Scobell, Leah Sava Jeffries, and Aryan Simhadri. I need to find their ages. I will search for “Walker Scobell age”.
Action 2
<search>Walker Scobell age</search>
Command: search, Query: Walker Scobell age
Observation 2
Could not find ["Walker Scobell age"]. Similar: {"results":[{"ns":0,"title":"Walker Scobell","pageid":70525114},{"ns":0,"title":"The Adam Project","pageid":65867428},{"ns":0,"title":"Percy Jackson","pageid":21327279},{"ns":0,"title":"Aryan Simhadri","pageid":74932124},{"ns":0,"title":"Walker (given name)","pageid":68329314},{"ns":0,"title":"Fairview Township, Erie County, Pennsylvania","pageid":132483},{"ns":0,"title":"Hiro Kanagawa","pageid":7200805},{"ns":0,"title":"January 5","pageid":19279054},{"ns":0,"title":"Deadpool & Wolverine","pageid":52234178},{"ns":0,"title":"List of characters played by multiple actors in the same film","pageid":6781845}]}. You should search for one of those instead.
Thought 3 I should search for the “Walker Scobell” page.
Action 3
<search>Walker Scobell</search>
Command: search, Query: Walker Scobell
Information Source: https://en.wikipedia.org/wiki/Walker_Scobell
Observation 3
This is a good, concise summary of Walker Scobell's career so far. It highlights key information like:
* **Nationality and birthplace:** American, born in Virginia.
* **Age and debut:** Began acting at age 13.
* **Early success:** Immediate recognition for lead roles in *The Adam Project* and *Secret Headquarters*.
* **Current leading role:** *Percy Jackson and the Olympians* on Disney+.
It effectively summarizes his career trajectory, starting with his breakthrough and ending with his current prominent role.
Thought 4 The summary says he began acting at age 13. I should look for his birthdate to calculate his age.
Action 4
<lookup>age</lookup>
Command: lookup, Query: age
Information Source: https://en.wikipedia.org/wiki/Walker_Scobell
Observation 4
Walker Scobell (born January 5, 2009) is an American actor. Born in Virginia, he made his professional acting debut at age 13 and gained immediate recognition for his lead roles in the science fiction streaming films The Adam Project and Secret Headquarters (both 2022). Scobell received continued recognition with his leading titular role in the Disney+ fantasy series Percy Jackson and the Olympians (2023–present).
== Life and career ==
=== Early life and acting background (2009–2021) ===
Scobell was born on January 5, 2009, in Virginia Beach, Virginia, to Heather Scobell and Pete Scobell in a military family. He has an older sister and younger brother. Scobell lived in Colorado until the family moved to Fairview, Pennsylvania, where his parents grew up. In elementary school, he attended drama class. He went to Fairview Middle School and acted in the school's production of Mary Poppins. Shortly after, he attended a John D'Aquino acting workshop, hired a manager and signed to an agency. When not traveling or on set, he goes to Fairview High School.
=== Acting breakthrough (2022–present) ===
Scobell au
Thought 5 Walker Scobell was born on January 5, 2009. It is currently November 26, 2024. So he is 15 years old. Now I need to find Leah Sava Jeffries’ age.
Action 5
<search>Leah Sava Jeffries age</search>
Command: search, Query: Leah Sava Jeffries age
Observation 5
Could not find ["Leah Sava Jeffries age"]. Similar: {"results":[{"ns":0,"title":"Leah Jeffries","pageid":74933311},{"ns":0,"title":"Aryan Simhadri","pageid":74932124},{"ns":0,"title":"Rel (TV series)","pageid":57387941},{"ns":0,"title":"Children's and Family Emmy Award for Outstanding Younger Performer","pageid":75815851},{"ns":0,"title":"Camp Half-Blood Chronicles","pageid":11155395},{"ns":0,"title":"X-Men","pageid":34218},{"ns":0,"title":"56th NAACP Image Awards","pageid":78827527},{"ns":0,"title":"A&F Quarterly","pageid":2963556},{"ns":0,"title":"List of American films of 2020","pageid":47216268},{"ns":0,"title":"List of victims of the September 11 attacks (O–Z)","pageid":71965641}]}. You should search for one of those instead.
Thought 6 I should search for “Leah Jeffries”.
Action 6
<search>Leah Jeffries</search>
Command: search, Query: Leah Jeffries
Information Source: https://en.wikipedia.org/wiki/Leah_Jeffries
Observation 6
This is a good, concise biography of Leah Sava Jeffries. It highlights key aspects of her career, including:
* **Her acting debut:** Empire (2015)
* **Her feature film debut:** Beast (2022)
* **Her breakthrough role:** Annabeth Chase in Percy Jackson & the Olympians
* **Her awards and nominations:** Two NAACP Image Awards and a Children's and Family Emmy Award nomination.
The information is accurate and presented in a clear, easy-to-understand manner. It effectively summarizes her rising prominence in the acting world.
Thought 7 I need to find her age.
Action 7
<lookup>age</lookup>
Command: lookup, Query: age
Information Source: https://en.wikipedia.org/wiki/Leah_Jeffries
Observation 7
Leah Sava Jeffries (; born September 25, 2009) is an American actress. Jeffries made her acting debut on the American musical drama, Empire (2015) and later her feature film debut in the action-thriller Beast (2022). In 2022, Jeffries was cast as Annabeth Chase in the television adaptation of Rick Riordan's fantasy novel series, Percy Jackson & the Olympians, which earned her two NAACP Image Awards, along with a nomination for the Children's and Family Emmy Award for Outstanding Younger Performer.
== Early life ==
Jeffries was born in Detroit, Michigan to Leah Jeffries and Floyd S. Jeffries Jr. She has an older brother, Floyd Jeffries, who is also an actor and model. She attended school in the Novi Community School District.
== Career ==
Prior to her acting debut, Jeffries worked as a model for children's products for Carol's Daughter. Jeffries' acting debut was at age 5 as Lola Lyon on Empire.
On May 5, 2022, Jeffries was announced as Annabeth Chase in Percy Jackson and the Olympians. Immediately following the casting announcement, Jeffries received harassment online because she was African-American, while her character, Annabeth Chase, was portrayed as white in the book series the show was based on. On May 10, the books' author, Rick Riordan, posted a blog post in which he condemned the backlash against Jeffries and reaffirmed his support of her. Alexandra Daddario,
Thought 8 Leah Sava Jeffries was born on September 25, 2009. It is currently November 26, 2024. So she is 15 years old. Now I need to find Aryan Simhadri’s age.
Action 8
<search>Aryan Simhadri age</search>
Command: search, Query: Aryan Simhadri age
Observation 8
Could not find ["Aryan Simhadri age"]. Similar: {"results":[{"ns":0,"title":"Aryan Simhadri","pageid":74932124},{"ns":0,"title":"Leah Jeffries","pageid":74933311},{"ns":0,"title":"Spin (2021 film)","pageid":63400176},{"ns":0,"title":"2006 in film","pageid":302754},{"ns":0,"title":"Hiro Kanagawa","pageid":7200805},{"ns":0,"title":"Savitribai Phule","pageid":4172250},{"ns":0,"title":"Freaky Friday (franchise)","pageid":63633041},{"ns":0,"title":"Sharat Saxena","pageid":12611800},{"ns":0,"title":"Cheaper by the Dozen (franchise)","pageid":61462161},{"ns":0,"title":"Camp Half-Blood Chronicles","pageid":11155395}]}. You should search for one of those instead.
Thought 9 I should search for “Aryan Simhadri”.
Action 9
<search>Aryan Simhadri</search>
Command: search, Query: Aryan Simhadri
Information Source: https://en.wikipedia.org/wiki/Aryan_Simhadri
Observation 9
This statement is accurate. Aryan Simhadri is indeed an American actor and is well-known for playing Grover Underwood in the Disney+ series "Percy Jackson and the Olympians."
Thought 10 I need to find his age.
Action 10
<lookup>age</lookup>
Command: lookup, Query: age
Information Source: https://en.wikipedia.org/wiki/Aryan_Simhadri
Observation 10
Aryan Simhadri ( ; born May 6, 2006) is an American actor best known for his role as Grover Underwood in the Disney+ series Percy Jackson and the Olympians. In 2021, Simhadri played Walter in the off-Broadway production of Trevor: The Musical.
== Career ==
Following short appearances in the comedy series Just Roll with It (2019) and the children's animated series Mira, Royal Detective (2020), Simhadri made his feature film debut with a supporting role in Netflix's The Main Event in 2020. His first starring role came in the Avantika Vandanapu-led Spin (2021) alongside Meera Syal and Abhay Deol. Simhadri followed this with a supporting role in Disney+'s Cheaper by the Dozen in 2022.
In 2023, Simhadri made a major breakthrough in his career with the Disney+ series, Percy Jackson and the Olympians, alongside Walker Scobell and Leah Sava Jeffries. Adapted from the novel of the same name, he played Grover Underwood, Jackson's satyr guardian. Writing for IndieWire, Proma Khosla described Simh
Thought 11 Aryan Simhadri was born on May 6, 2006. It is currently November 26, 2024. So he is 18 years old.
Walker Scobell is 15. Leah Sava Jeffries is 15. Aryan Simhadri is 18.
15 + 15 + 18 = 48
Action 11
<finish>The total of the ages of the main trio from the new Percy Jackson and the Olympians TV series in real life is 48.</finish>
Command: finish, Query: The total of the ages of the main trio from the new Percy Jackson and the Olympians TV series in real life is 48.
Information Sources: https://en.wikipedia.org/wiki/Percy_Jackson_and_the_Olympians_(TV_series),https://en.wikipedia.org/wiki/Walker_Scobell,https://en.wikipedia.org/wiki/Leah_Jeffries,https://en.wikipedia.org/wiki/Aryan_Simhadri
Now, try asking the same question to gemini-2.0-flash model without the ReAct prompt.
const response =await ai.models.generateContent({ model: MODEL_ID, contents:"What are the total of ages of the main trio from the new Percy Jackson and the Olympians TV series in real life?",});console.log(response.text??"No response text available.");
Okay, here are the real-life ages of the actors who play the main trio in the new *Percy Jackson and the Olympians* TV series, and their combined age:
* **Walker Scobell (Percy Jackson):** Born January 6, 2009, making him **15 years old**.
* **Leah Sava Jeffries (Annabeth Chase):** Born September 25, 2011, making her **12 years old**.
* **Aryan Simhadri (Grover Underwood):** Born June 6, 2006, making him **17 years old**.
**Total:** 15 + 12 + 17 = **44 years**
The combined age of the main trio is 44 years.
Summary
The ReAct prompted Gemini model is grounded by external information sources and hence is less prone to hallucination. Furthermore, Thought-Action-Observation traces generated by the model enhance human interpretability and trustworthiness by allowing users to witness the model’s reasoning process for answering the user’s query.