Section 4 of Building Agentic AI Applications with LLMs

Abstract

This section details the architectural transition from stateless large language model (LLM) interfaces to structured agentic systems capable of local perception and action within a defined environment. It establishes the fundamental agent loop—converting global state to local perception, executing semantic action, and updating the global state—as the core mechanism for managing multi-agent interactions. The technical contribution lies in comparing state management patterns, specifically contrasting monolithic central states against distributed local states to mitigate information asymmetry and semantic drift in complex agent systems.

Key Concepts

  • Semantic Agency and Local Perception: An agent is defined technically as an entity existing within an environment where its functionality is derived from local perception driving local action. Unlike a monolithic LLM response which is stateless, an agent must sustain an internal thought process and local perspective to navigate an environment with defined goals and tasks. This requires mapping semantically-dense inputs to outputs through an interface understandable by both humans and algorithms.
  • Semantic Reasoning via Encoding Models: To model the mapping from semantically-meaningful input to output, the system utilizes an Encoding Model represented as . This construct maps inputs with intuitive explicit form, such as actual text, to implicit numerical representations, typically high-dimensional vectors, allowing the system to process meaning within a latent space rather than just raw tokens.
  • Decoding and Latent Representation: Complementing the encoder, the Decoding Model, represented as , maps input from some representation, such as a vector or explicit text, into an explicit output representation. These constructs are highly general and support various architectures, including text-generation where implicit latent forms are iteratively converted back into explicit sequences.
  • Abstraction Layers in Inference: Between a user request and the final response, the system operates through multiple layers of abstraction including network requests, microservice orchestration, and tokenization. The workflow involves inserting inputs into prompt templates, converting strings to classes via preprocessing pipelines, embedding them into latent forms, and propagating them through a transformer-backed architecture before progressive decoding of next tokens.
  • LangChain Expression Language (LCEL): LCEL provides a compositional interface for constructing pipelines where data flows from a dictionary through formatted prompts to an LLM and finally to a response object. Components are implemented as Runnables with .invoke() and .stream() methods, connected via Unix-style pipes to chain operations like template filling, model invocation, and output parsing.
  • State Management Patterns: Effective agent systems require managing environment state, whether as a single global state or distributed local states. The central pattern involves converting a global environment list of messages into a local perception view for each agent, ensuring that the agent’s context is filtered and relevant to its specific identity and role.
  • Central State (Global Truth): In this pattern, all messages are committed to a single shared central state list, serving as the source of truth for the entire environment. Each agent’s local perception is derived by filtering this central state, and any local action updates the central state directly, ensuring coherence across the conversation history.
  • Distributed Local States and Witnesses: Alternatively, agents can maintain independent message lists where information is shared only via a witness mechanism. In this configuration, agents do not inherently share state; when an interaction occurs, witnesses must record the event in their own local state to prevent information asymmetry between participants.
  • Semantic Drift: Drift occurs in multi-state systems when agents maintain local memories that are not synchronized with the external environment or other agents. If witnesses do not record every interaction, agents accumulate contradictory information over time, leading to a breakdown in shared reality and coherent system behavior.

Key Equations and Algorithms

  • Encoding Model Definition: This equation defines the mapping of explicit input (such as text) to an implicit numerical representation in an -dimensional real vector space, allowing the model to process semantic meaning mathematically.
  • Decoding Model Definition: This function describes the mapping from a latent representation or explicit input into a final explicit output , enabling the reconstruction of tokens or objects from the implicit semantic space.
  • Token Sequence Probability: This expression calculates the probability of generating a sequence of tokens given preceding tokens, which is iteratively computed as for token generation.
  • Token Generation Loop: The agent invokes get_next_interaction which calls chat_chain.invoke(state) to generate the next message. This process involves filling a template with state variables, processing through the LLM, and parsing the output into a string.
  • Central State Update Algorithm: To update the global environment, the system executes central_state += [(speaker, message)]. This appends the agent’s response to the single source of truth, ensuring the next agent can perceive the full conversation context.
  • State Conversion Function: The function get_messages(p1, central_state) converts the global state into a local perception list. It assigns roles such as “user” to the sender and “ai” to others, formatting the content for the specific agent’s context.

Key Claims and Findings

  • Default LLM endpoints are stateless and do not inherently constitute agents without engineered memory or state management loops.
  • Monolithic systems feeding the entire history to every query fail to model local perception, which is required for true agency.
  • Central State patterns provide functional coherence by ensuring all agents share the same underlying truth, though they require filtering logic for individual views.
  • Distributed Local State patterns without a witness mechanism result in incoherent conversations due to a lack of shared context between agents.
  • The fundamental agent loop consists of three distinct steps: converting global state to local perception, generating a local action in semantic space, and modifying the global state based on that action.
  • Prompting strategies such as few-shot examples are required to lock down output formats, although they may degrade performance if the exemplified outputs are unreasonable.
  • System messages are critical for establishing behavior but must be engineered carefully as some models may ignore them or interpret them as input rather than directives.

Terminology

  • Agent: An entity within an environment that operates based on local perception driving local actions, distinct from a stateless LLM by its ability to sustain internal thought and perspective.
  • Semantic Space: The mathematical construct where semantically-meaningful inputs and outputs are mapped, typically represented as high-dimensional vectors or latent forms.
  • Local Perception: The filtered view of the environment state available to a specific agent, distinct from the total global state of the system.
  • Global State: The complete environment configuration containing all messages and history, often implemented as a single shared list in centralized architectures.
  • Central State: A specific state management architecture where all messages are appended to one shared data structure that serves as the single source of truth for the system.
  • Witnesses: A mechanism in distributed state architectures where agents copy interactions into their local state when they observe a conversation, ensuring information propagation.
  • Drift: The divergence of agent internal states from the actual environment reality caused by information asymmetry in distributed local memory systems.
  • Runnable: An interface component in LCEL that possesses .invoke() and .stream() methods, allowing it to be chained with other components in an execution pipeline.
  • Semantic Drift: The long-term degradation of system coherence that occurs when agents in a multi-agent system hold conflicting versions of reality due to incomplete state synchronization.