news-agent

🤖 News Agent

1. Introduction

The News Agent is a stateful, streaming LLM orchestration system designed to perform iterative research and information synthesis. It combines structured tool usage, graph-based execution, and multi-model reasoning to deliver context-aware responses.

Unlike simple chatbot implementations, this system separates:


2. Core Capabilities


3. Architecture Overview

The agent is built using a graph-based execution model powered by StateGraph, where each node represents a distinct stage in the reasoning pipeline.

High-Level Flow

User Query → Decision → Keyword Extraction → Tool Invocation → Tool Summarization → LLM Response → Streaming Output

4. Key Components

4.1 Execution Engine


4.2 LLM Strategy

Two models are used for optimized performance:

This reduces cost and latency while preserving output quality.


4.3 Streaming Layer


5. Execution Graph (Nodes)

The system consists of the following nodes:

5.1 Data Fetch Decision Node


5.2 Keyword Extraction Node


5.3 Tools Node


5.4 Tool Output Summarization Node


5.5 Chat Summarization Node


5.6 LLM Node


6. MCP Integration

The agent integrates with an external MCP server using:

Available Capabilities

Design Principle


7. State Management

The system maintains state across execution and sessions using:

Responsibilities


8. Guided Exploration

This enables:


9. Streaming Behavior

Each node emits intermediate outputs which are streamed via FastAPI:

This provides:


10. Design Philosophy


11. Limitations


12. Security & Access Model

This service is not designed for direct public access and is intended to operate behind a secure gateway layer.

CORS Policy

CORS is not enabled in this FastAPI service.

Rationale

Architecture Enforcement

Client (Browser/UI) → Gateway → Agent → MCP Server

This ensures:

Development Note

If direct browser access is required for local development or testing, CORS can be temporarily enabled. However, it is intentionally excluded in the default setup to maintain architectural integrity.


13. Input & Output Contract

Request Format

The agent is exposed via a streaming HTTP endpoint using FastAPI.

Request Body (example):

{
  "user_id": "user_123",
  "thread_id": "thread_456",
  "query": "Explain latest developments in AI regulation"
}

Fields

Response Format (Streaming)

The agent responds using a streaming interface, where each chunk represents intermediate execution updates.

Example Stream Events:

{"type":"node","node_name":"data_fetch_decision_node","node_output":"Determining if external data is required..."}
{"type":"node","node_name":"keyword_extraction_node","node_output":"AI regulation, policy updates, global AI laws"}
{"type":"node","node_name":"tool_output_summarize_node","node_output":"Summarized key articles..."}
{"type":"node","node_name":"llm_node","node_output":"Recent developments in AI regulation include..."}
{"type":"done"}

Design Considerations


14. Environment Configuration

The agent requires the following environment variables to be set before running.

Required Variables

# OpenAI / LLM Configuration
OPENAI_API_KEY=your_api_key

# Database Configuration (PostgreSQL)
POSTGRES_CHECKPOINTER_URI=postgresql://admin:admin@news-agent-postgres:5432/newsagent

# MCP Server Configuration
MCP_URI=http://localhost:8000/mcp

Description


15. Future Enhancements


Final Note

This agent is designed as a control and intelligence layer in a modular LLM system. Its strength lies in:

It is best deployed alongside:


👤 Maintainer

Tuhin Kumar Dutta


⭐ Contribute

Pull requests and issues are welcome.

git clone https://github.com/tuhindutta/news-agent.git

DockerHub: https://hub.docker.com/r/tkdutta/news-agent