Skip to main content
Paper·arxiv.org
ai-agentsllminfrastructurecontext-engineeringautomationresearchpsi

PSI: Shared State as the Missing Layer for Coherent AI-Generated Instruments in Personal AI Agents

Implement the Persistent Shared-state Instruments (PSI) architecture to overcome isolated AI tools. Introduce a shared state layer, enabling AI agents to maintain context and create coherent, integrated workflows beyond single-shot operations.

intermediate30 min5 steps
The play
  1. Identify Isolated AI Tools
    Recognize the limitations of current AI tools operating without shared context or persistent memory. Understand how this isolation prevents complex, multi-step agent behaviors.
  2. Design a Shared State Layer
    Create a central, persistent data store or service that is accessible by all your AI modules and instruments. This layer will hold dynamic context, intermediate results, and agent memory.
  3. Instrument AI Modules for State Interaction
    Modify or design your individual AI tools (e.g., search, generation, summarization) to read from and write to this shared state layer. Ensure they can both consume existing context and contribute new information.
  4. Enable Contextual Persistence
    Implement mechanisms to ensure the shared state maintains relevant context across multiple interactions, tool invocations, and even sessions. This facilitates multi-step reasoning and coherent user experiences.
  5. Integrate with Agent Orchestration
    Connect these shared-state instruments within your Personal AI Agent framework. Orchestrate tool usage to leverage the persistent context, enabling complex, chat-complementary, and intelligent workflows.
Starter code
class AgentSharedState:
    def __init__(self):
        self.context = {}
        self.tool_outputs = []
        self.user_preferences = {}

    def update_context(self, key: str, value: any):
        self.context[key] = value

    def add_tool_output(self, output: str):
        self.tool_outputs.append(output)

    def get_state(self):
        return {
            "context": self.context,
            "tool_outputs": self.tool_outputs,
            "user_preferences": self.user_preferences
        }

def example_ai_instrument(query: str, shared_state: AgentSharedState):
    """Simulates an AI tool interacting with the shared state."""
    # Read from shared state (e.g., user preferences)
    if "language" in shared_state.user_preferences:
        print(f"Using preferred language: {shared_state.user_preferences['language']}")

    # Perform tool action
    result = f"Processed query '{query}' and generated a report."

    # Write to shared state
    shared_state.add_tool_output(result)
    shared_state.update_context("last_processed_query", query)
    print(f"Instrument executed. Shared state updated.")
    return result

# Initialize the shared state for an agent
agent_state = AgentSharedState()
agent_state.update_context("current_user", "Alice")
agent_state.user_preferences["language"] = "English"

# An AI agent orchestrates tool usage, passing the shared state
print(f"Initial agent state: {agent_state.get_state()}")
example_ai_instrument("summarize recent news", agent_state)
print(f"State after first instrument: {agent_state.get_state()}")

# Another instrument or subsequent agent action can now access the updated state
print(f"Agent's current context from shared state: {agent_state.context}")
Source
PSI: Shared State as the Missing Layer for Coherent AI-Generated Instruments in Personal AI Agents — Action Pack