Close Menu
  • Home
  • Opinion
  • Region
    • Africa
    • Asia
    • Europe
    • Middle East
    • North America
    • Oceania
    • South America
  • AI & Machine Learning
  • Robotics & Automation
  • Space & Deep Tech
  • Web3 & Digital Economies
  • Climate & Sustainability Tech
  • Biotech & Future Health
  • Mobility & Smart Cities
  • Global Tech Pulse
  • Cybersecurity & Digital Rights
  • Future of Work & Education
  • Trend Radar & Startup Watch
  • Creator Economy & Culture
What's Hot

Do you have to promote your Kraken Robotics inventory?

January 18, 2026

India courts world buyers at Davos with AI-led development message

January 18, 2026

Agibot Opens Its First Abroad Expertise Heart in Malaysia, Marking a Key Step in International Growth

January 18, 2026
Facebook X (Twitter) Instagram LinkedIn RSS
NextTech NewsNextTech News
Facebook X (Twitter) Instagram LinkedIn RSS
  • Home
  • Africa
  • Asia
  • Europe
  • Middle East
  • North America
  • Oceania
  • South America
  • Opinion
Trending
  • Do you have to promote your Kraken Robotics inventory?
  • India courts world buyers at Davos with AI-led development message
  • Agibot Opens Its First Abroad Expertise Heart in Malaysia, Marking a Key Step in International Growth
  • Transdev companions to launch East Bay paratransit service
  • Flexxbotics Releases Free Obtain of Software program-Outlined Automation for Manufacturing Autonomy
  • Why reinforcement studying plateaus with out illustration depth (and different key takeaways from NeurIPS 2025)
  • 3 Excessive-Progress Industries Value Getting Into
  • AI Utopianism Masks Tech Billionaires’ Worry: Douglas Rushkoff
Sunday, January 18
NextTech NewsNextTech News
Home - AI & Machine Learning - Find out how to Construct a Self-Evaluating Agentic AI System with LlamaIndex and OpenAI Utilizing Retrieval, Software Use, and Automated High quality Checks
AI & Machine Learning

Find out how to Construct a Self-Evaluating Agentic AI System with LlamaIndex and OpenAI Utilizing Retrieval, Software Use, and Automated High quality Checks

NextTechBy NextTechJanuary 18, 2026No Comments4 Mins Read
Share Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email Copy Link
Follow Us
Google News Flipboard
Find out how to Construct a Self-Evaluating Agentic AI System with LlamaIndex and OpenAI Utilizing Retrieval, Software Use, and Automated High quality Checks
Share
Facebook Twitter LinkedIn Pinterest Email


On this tutorial, we construct a sophisticated agentic AI workflow utilizing LlamaIndex and OpenAI fashions. We deal with designing a dependable retrieval-augmented technology (RAG) agent that may purpose over proof, use instruments intentionally, and consider its personal outputs for high quality. By structuring the system round retrieval, reply synthesis, and self-evaluation, we exhibit how agentic patterns transcend easy chatbots and transfer towards extra reliable, controllable AI programs appropriate for analysis and analytical use circumstances.

!pip -q set up -U llama-index llama-index-llms-openai llama-index-embeddings-openai nest_asyncio


import os
import asyncio
import nest_asyncio
nest_asyncio.apply()


from getpass import getpass


if not os.environ.get("OPENAI_API_KEY"):
   os.environ["OPENAI_API_KEY"] = getpass("Enter OPENAI_API_KEY: ")

We arrange the surroundings and set up all required dependencies for operating an agentic AI workflow. We securely load the OpenAI API key at runtime, guaranteeing that credentials are by no means hardcoded. We additionally put together the pocket book to deal with asynchronous execution easily.

from llama_index.core import Doc, VectorStoreIndex, Settings
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding


Settings.llm = OpenAI(mannequin="gpt-4o-mini", temperature=0.2)
Settings.embed_model = OpenAIEmbedding(mannequin="text-embedding-3-small")


texts = [
   "Reliable RAG systems separate retrieval, synthesis, and verification. Common failures include hallucination and shallow retrieval.",
   "RAG evaluation focuses on faithfulness, answer relevancy, and retrieval quality.",
   "Tool-using agents require constrained tools, validation, and self-review loops.",
   "A robust workflow follows retrieve, answer, evaluate, and revise steps."
]


docs = [Document(text=t) for t in texts]
index = VectorStoreIndex.from_documents(docs)
query_engine = index.as_query_engine(similarity_top_k=4)

We configure the OpenAI language mannequin and embedding mannequin and construct a compact data base for our agent. We remodel uncooked textual content into listed paperwork in order that the agent can retrieve related proof throughout reasoning.

from llama_index.core.analysis import FaithfulnessEvaluator, RelevancyEvaluator


faith_eval = FaithfulnessEvaluator(llm=Settings.llm)
rel_eval = RelevancyEvaluator(llm=Settings.llm)


def retrieve_evidence(q: str) -> str:
   r = query_engine.question(q)
   out = []
   for i, n in enumerate(r.source_nodes or []):
       out.append(f"[{i+1}] {n.node.get_content()[:300]}")
   return "n".be part of(out)


def score_answer(q: str, a: str) -> str:
   r = query_engine.question(q)
   ctx = [n.node.get_content() for n in r.source_nodes or []]
   f = faith_eval.consider(question=q, response=a, contexts=ctx)
   r = rel_eval.consider(question=q, response=a, contexts=ctx)
   return f"Faithfulness: {f.rating}nRelevancy: {r.rating}"

We outline the core instruments utilized by the agent: proof retrieval and reply analysis. We implement automated scoring for faithfulness and relevancy so the agent can decide the standard of its personal responses.

from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.workflow import Context


agent = ReActAgent(
   instruments=[retrieve_evidence, score_answer],
   llm=Settings.llm,
   system_prompt="""
At all times retrieve proof first.
Produce a structured reply.
Consider the reply and revise as soon as if scores are low.
""",
   verbose=True
)


ctx = Context(agent)

We create the ReAct-based agent and outline its system habits, guiding the way it retrieves proof, generates solutions, and revises outcomes. We additionally initialize the execution context that maintains the agent’s state throughout interactions. It step brings collectively instruments and reasoning right into a single agentic workflow.

async def run_brief(subject: str):
   q = f"Design a dependable RAG + tool-using agent workflow and methods to consider it. Subject: {subject}"
   handler = agent.run(q, ctx=ctx)
   async for ev in handler.stream_events():
       print(getattr(ev, "delta", ""), finish="")
   res = await handler
   return str(res)


subject = "RAG agent reliability and analysis"
loop = asyncio.get_event_loop()
outcome = loop.run_until_complete(run_brief(subject))


print("nnFINAL OUTPUTn")
print(outcome)

We execute the total agent loop by passing a subject into the system and streaming the agent’s reasoning and output. We permit the agent to finish its retrieval, technology, and analysis cycle asynchronously.

In conclusion, we showcased how an agent can retrieve supporting proof, generate a structured response, and assess its personal faithfulness and relevancy earlier than finalizing a solution. We saved the design modular and clear, making it straightforward to increase the workflow with further instruments, evaluators, or domain-specific data sources. This strategy illustrates how we are able to use agentic AI with LlamaIndex and OpenAI fashions to construct extra succesful programs which are additionally extra dependable and self-aware of their reasoning and responses.


Try the FULL CODES right here. Additionally, be happy to comply with us on Twitter and don’t overlook to hitch our 100k+ ML SubReddit and Subscribe to our E-newsletter. Wait! are you on telegram? now you possibly can be part of us on telegram as properly.


Asif Razzaq is the CEO of Marktechpost Media Inc.. As a visionary entrepreneur and engineer, Asif is dedicated to harnessing the potential of Synthetic Intelligence for social good. His most up-to-date endeavor is the launch of an Synthetic Intelligence Media Platform, Marktechpost, which stands out for its in-depth protection of machine studying and deep studying information that’s each technically sound and simply comprehensible by a large viewers. The platform boasts of over 2 million month-to-month views, illustrating its reputation amongst audiences.

Elevate your perspective with NextTech Information, the place innovation meets perception.
Uncover the newest breakthroughs, get unique updates, and join with a world community of future-focused thinkers.
Unlock tomorrow’s developments at present: learn extra, subscribe to our e-newsletter, and grow to be a part of the NextTech group at NextTech-news.com

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
NextTech
  • Website

Related Posts

NVIDIA Releases PersonaPlex-7B-v1: A Actual-Time Speech-to-Speech Mannequin Designed for Pure and Full-Duplex Conversations

January 18, 2026

Black Forest Labs Releases FLUX.2 [klein]: Compact Stream Fashions for Interactive Visible Intelligence

January 16, 2026

Google AI Releases TranslateGemma: A New Household of Open Translation Fashions Constructed on Gemma 3 with Assist for 55 Languages

January 16, 2026
Add A Comment
Leave A Reply Cancel Reply

Economy News

Do you have to promote your Kraken Robotics inventory?

By NextTechJanuary 18, 2026

Nationwide Financial institution Monetary analyst Mike Stevens downgraded Kraken Robotics to “Sector Carry out” from…

India courts world buyers at Davos with AI-led development message

January 18, 2026

Agibot Opens Its First Abroad Expertise Heart in Malaysia, Marking a Key Step in International Growth

January 18, 2026
Top Trending

Do you have to promote your Kraken Robotics inventory?

By NextTechJanuary 18, 2026

Nationwide Financial institution Monetary analyst Mike Stevens downgraded Kraken Robotics to “Sector…

India courts world buyers at Davos with AI-led development message

By NextTechJanuary 18, 2026

India is gearing up for a high-profile presence on the World Financial…

Agibot Opens Its First Abroad Expertise Heart in Malaysia, Marking a Key Step in International Growth

By NextTechJanuary 18, 2026

In accordance with IPO Zaozhidao, Agibot formally opened its first abroad robotic…

Subscribe to News

Get the latest sports news from NewsSite about world, sports and politics.

NEXTTECH-LOGO
Facebook X (Twitter) Instagram YouTube

AI & Machine Learning

Robotics & Automation

Space & Deep Tech

Web3 & Digital Economies

Climate & Sustainability Tech

Biotech & Future Health

Mobility & Smart Cities

Global Tech Pulse

Cybersecurity & Digital Rights

Future of Work & Education

Creator Economy & Culture

Trend Radar & Startup Watch

News By Region

Africa

Asia

Europe

Middle East

North America

Oceania

South America

2025 © NextTech-News. All Rights Reserved
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms Of Service
  • Advertise With Us
  • Write For Us
  • Submit Article & Press Release

Type above and press Enter to search. Press Esc to cancel.

Subscribe For Latest Updates

Sign up to best of Tech news, informed analysis and opinions on what matters to you.

Invalid email address
 We respect your inbox and never send spam. You can unsubscribe from our newsletter at any time.     
Thanks for subscribing!