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

FPIs withdraw $2.5B from Indian shares to date this month

January 18, 2026

AI Brokers Are Changing into Authorization Bypass Paths

January 18, 2026

Beating The World Report For Quickest Flying Drone As soon as Once more

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
  • FPIs withdraw $2.5B from Indian shares to date this month
  • AI Brokers Are Changing into Authorization Bypass Paths
  • Beating The World Report For Quickest Flying Drone As soon as Once more
  • X says it’ll lastly cease letting Grok create undressed pictures of individuals
  • His Excellency Sheikh Nahyan bin Mubarak Al Nahyan crowns winner of Longines Grand Prix class at FBMA Worldwide Present Leaping Cup 2026
  • Mario’s Tiny Odyssey Has Him Conquering the Apple Watch
  • Beijing Completes Rocket Road, China’s First Shared Testing and R&D Manufacturing Base for Industrial Spaceflight
  • One Maker Turned 3,200 Matches right into a Single Working Large
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

FPIs withdraw $2.5B from Indian shares to date this month

By NextTechJanuary 18, 2026

International portfolio buyers withdrew greater than Rs 22,530 crore ($2.5 billion) from Indian equities to…

AI Brokers Are Changing into Authorization Bypass Paths

January 18, 2026

Beating The World Report For Quickest Flying Drone As soon as Once more

January 18, 2026
Top Trending

FPIs withdraw $2.5B from Indian shares to date this month

By NextTechJanuary 18, 2026

International portfolio buyers withdrew greater than Rs 22,530 crore ($2.5 billion) from…

AI Brokers Are Changing into Authorization Bypass Paths

By NextTechJanuary 18, 2026

Not way back, AI brokers had been innocent. They wrote snippets of…

Beating The World Report For Quickest Flying Drone As soon as Once more

By NextTechJanuary 18, 2026

The enjoyable half about world data is that anybody can take a…

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!