Creating Hierarchical AI Assistant Contexts: Global vs. Project-Specific Configurations

Published: (February 3, 2026 at 02:56 PM EST)
5 min read
Source: Dev.to

Source: Dev.to

Peter Eichhorst

Introduction

This article stems from a real challenge I encountered while developing and managing an AI assistant that needed to operate effectively across multiple contexts. The problem emerged when the same assistant had to handle both general system‑administration tasks and highly specialized project work within specific codebases.

Initially, the AI assistant experienced context confusion—responding with general knowledge when working on specialized projects, or applying project‑specific rules inappropriately to general tasks. This led to inconsistent behavior and reduced effectiveness.

The solution I developed involved creating a robust separation and hierarchy between global and project‑specific AI assistant configurations, ensuring context‑aware behavior without confusion. This approach allows the assistant to maintain its core safety and operational principles while specializing its behavior based on the current project context.

The Problem: Context Confusion

Without proper configuration hierarchies, AI assistants can experience identity confusion when switching between different scopes of work. For example, an assistant might:

  • Respond with general system‑administration knowledge while working on a specific software project, or
  • Apply project‑specific rules to a general task.

Both scenarios lead to inconsistent behavior and reduced effectiveness.

Solution Overview

The solution involves creating layered configuration files that establish clear priority and context‑switching mechanisms:

  1. Global Configuration – Base rules that apply everywhere.
  2. Project‑Specific Configuration – Specialized rules for individual projects.
  3. Dynamic Context Detection – Automatic switching based on the current directory.
  4. Clear Hierarchy – Well‑defined priority when conflicts arise.

Implementation Strategy

1. Global Configuration Foundation

The global configuration serves as the base layer with essential rules that apply universally:

# global-config.yml
assistant:
  name: "Universal AI Assistant"
  safety:
    enabled: true
    policies:
      - no-harm
      - privacy-first
  logging:
    level: info
    destination: /var/log/assistant/global.log
  defaults:
    temperature: 0.7
    max_tokens: 1500

Explanation

  • Safety policies are enforced everywhere.
  • Logging is centralized for audit purposes.
  • Defaults provide a consistent baseline for all interactions.

2. Project‑Specific Configuration

Each project can override or extend the global settings:

# .assistant/project-config.yml
assistant:
  name: "Project‑X AI Assistant"
  defaults:
    temperature: 0.3   # More deterministic for code generation
    max_tokens: 800
  extensions:
    - linting-helper
    - test‑generator
  context:
    root: "./src"
    language: "python"

Key points

  • Overrides temperature for more predictable outputs.
  • Adds project‑specific extensions (e.g., linting, test generation).
  • Defines the project root and primary language for dynamic context detection.

3. Dynamic Context Detection

A small wrapper script detects the current working directory and loads the appropriate configuration:

#!/usr/bin/env python3
import os
import yaml

def load_config():
    cwd = os.getcwd()
    # Walk up the directory tree looking for a project config
    while cwd != "/":
        proj_cfg_path = os.path.join(cwd, ".assistant", "project-config.yml")
        if os.path.isfile(proj_cfg_path):
            with open(proj_cfg_path) as f:
                return yaml.safe_load(f)
        cwd = os.path.dirname(cwd)

    # Fallback to global config
    with open("/etc/assistant/global-config.yml") as f:
        return yaml.safe_load(f)

config = load_config()
print(f"Loaded configuration for: {config['assistant']['name']}")

The script:

  1. Starts at the current directory.
  2. Traverses upward until it finds a .assistant/project-config.yml.
  3. Falls back to the global configuration if none is found.

4. Clear Hierarchy & Conflict Resolution

When both global and project configurations define the same key, the project‑specific value wins. This can be enforced programmatically:

def merge_configs(global_cfg, project_cfg):
    merged = global_cfg.copy()
    for key, value in project_cfg.items():
        if isinstance(value, dict) and key in merged:
            merged[key] = merge_configs(merged[key], value)
        else:
            merged[key] = value
    return merged

The merging strategy ensures:

  • Deep merging for nested dictionaries.
  • Project‑level overrides take precedence.

Benefits

  • Predictable behavior: The assistant knows which rule set to apply based on context.
  • Safety first: Global safety policies are never bypassed.
  • Scalability: Adding new projects only requires a small config file.
  • Maintainability: Centralized global settings reduce duplication.

Conclusion

By establishing a clear hierarchy—global defaults, project‑specific overrides, and dynamic detection—you can eliminate context confusion and provide a reliable, safe, and adaptable AI assistant across diverse workloads. This pattern is language‑agnostic and can be adapted to any tooling ecosystem that supports hierarchical configuration files.

Every Session Protocol

  1. Read core identity files (SOUL.md, USER.md)
  2. Load memory context
  3. Check for project‑specific configs in the current directory
  4. Apply project rules with priority when applicable
  5. Report current‑directory context when relevant

2. Project‑Specific Configuration

Each project maintains its own configuration files that specialize the assistant’s behavior:

FilePurpose
SOUL.mdProject‑specific personality and priorities
IDENTITY.mdRole‑specific identity and communication style
USER.mdProject team members and their preferences
AGENTS.mdProject‑specific workflows and processes
MEMORY.mdImportant project notes (optional)

3. Dynamic Context Detection

The assistant should automatically detect and adapt to the current project context.

// Pseudocode for context detection
if (current_directory.hasProjectConfigs()) {
  const projectIdentity = loadProjectIdentity(current_directory);
  const globalRules = loadGlobalRules();
  return mergeConfigs(projectIdentity, globalRules, { priority: "project" });
} else {
  return loadGlobalRules();
}

4. Clear Hierarchy and Conflict Resolution

DomainRule
Development TasksProject rules take priority
Safety / EthicsGlobal safety rules always take precedence
Operational TasksApply both sets of rules appropriately
Identity QuestionsPresent project role first, then general capabilities

Best Practices

1. Consistent File Structure

Maintain the same configuration file layout across all projects:

  • SOUL.md – personality and values
  • IDENTITY.md – specific role definition
  • USER.md – team member information
  • AGENTS.md – workflow and processes
  • MEMORY.md – important project notes (optional)

2. Explicit Context Reporting

  • Report the current directory when relevant.
  • Clarify your role based on the detected context.
  • Explain when you switch between contexts.

3. Seamless Transitions

  • Detect context changes automatically.
  • Apply the appropriate rules without user intervention.
  • Preserve continuity across context switches.

4. Safety‑First Approach

  • Global safety rules override any project‑specific rules.
  • Maintain privacy protections regardless of context.
  • Preserve core ethical constraints at all times.

Benefits of This Approach

  • Context‑Aware Behavior – Responses adapt to the current project.
  • Reduced Confusion – Clear identity and role definitions prevent mixing contexts.
  • Scalability – New projects can be added with their own specialized configurations.
  • Consistency – Core safety and operational principles remain intact.
  • Flexibility – Handles both specialized and general tasks effectively.

Real‑World Example

Scenario: An AI assistant works on system administration and a specific web‑application project.

ContextFocus
GlobalSystem operations, file management, general productivity
Web‑App ProjectCoding, testing, deployment, project‑specific workflows
  • Identity – Always explain both general capabilities and the project‑specific role.
  • Safety – The same security and privacy measures apply in both contexts.

Conclusion

A hierarchical AI‑assistant configuration system enables specialized project work while retaining general utility. By implementing automatic context detection, clear priority rules, and seamless transitions, assistants become more effective in specific domains and remain reliable for general tasks. The key is to design the system with:

  • Automatic context detection
  • Explicit hierarchy (project > global, with safety always on top)
  • Transparent reporting of the active context

This structure enhances the user experience without adding unnecessary complexity.

Back to Blog

Related posts

Read more »