Skip to content

Conversation

@cyhhao
Copy link

@cyhhao cyhhao commented Nov 13, 2025

Summary

  • remember the directory of the resolved config file
  • resolve graph file paths relative to that directory instead of CWD
  • return string paths in list_graphs() for clearer logs

Testing

  • verified locally that langgraph.json entries using relative paths load correctly when the config lives outside the graphs directory

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the LangGraphService to resolve graph file paths relative to the configuration file's directory instead of the current working directory. This enables more flexible configuration file placement, particularly when the config lives outside the graphs directory.

Key Changes:

  • Store the configuration file's parent directory during initialization
  • Resolve relative graph paths against the config directory
  • Convert Path objects to strings in list_graphs() for clearer logging

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def _load_graph_registry(self):
"""Load graph definitions from aegra.json"""
graphs_config = self.config.get("graphs", {})
config_dir = self.config_dir or Path.cwd()
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The fallback config_dir = self.config_dir or Path.cwd() is defensive, but _load_graph_registry() is only called from initialize(), where self.config_dir is guaranteed to be set on line 64. The fallback to Path.cwd() could mask bugs where the service is not properly initialized.

Consider either:

  1. Removing the fallback and trusting that initialization has occurred:
    config_dir = self.config_dir
  2. Adding an assertion to make the requirement explicit:
    assert self.config_dir is not None, "Service must be initialized before loading graph registry"
    config_dir = self.config_dir

This makes the initialization contract clearer and helps catch misuse earlier.

Suggested change
config_dir = self.config_dir or Path.cwd()
assert self.config_dir is not None, "Service must be initialized before loading graph registry"
config_dir = self.config_dir

Copilot uses AI. Check for mistakes.
if ":" not in graph_path:
raise ValueError(f"Invalid graph path format: {graph_path}")

file_path, export_name = graph_path.split(":", 1)
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a docstring comment above this block to explain the path resolution logic, especially since this is a key feature of the PR. For example:

# Resolve graph file paths relative to config directory.
# Relative paths are resolved against config_dir, absolute paths are used as-is.
resolved_path = Path(file_path)
if not resolved_path.is_absolute():
    resolved_path = (config_dir / resolved_path).resolve()

This would make the intent clearer for future maintainers.

Suggested change
file_path, export_name = graph_path.split(":", 1)
file_path, export_name = graph_path.split(":", 1)
# Resolve graph file paths relative to config directory.
# Relative paths are resolved against config_dir, absolute paths are used as-is.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants