Skip to content

Conversation

@PieterPel
Copy link

Add TypeScript/JavaScript Graph Support

Description

Add proof-of-concept support for TypeScript and JavaScript graphs alongside existing Python graphs.
This allows developers to write LangGraph agents in TypeScript/JavaScript that execute via Node.js or Bun while sharing the same PostgreSQL state persistence as Python graphs.
I am very much open to hearing feedback and suggestions on this PR.

Type of Change

  • feat: New feature
  • test: Tests added/updated
  • docs: Documentation changes

Related Issues

N/A - New feature addition

Changes Made

Core Implementation

  • Add TypeScript runtime manager with subprocess execution and IPC communication
  • Add configuration parser to detect and validate TypeScript graphs
  • Extend LangGraphService to support both Python and TypeScript graphs
  • Add TypeScript wrapper for graph execution with PostgreSQL checkpointer integration
  • Add JS_RUNTIME environment variable for runtime selection (auto/node/bun)

TypeScript SDK

  • Complete TypeScript SDK with client implementation
  • Type definitions for all Aegra API endpoints
  • Example TypeScript graph demonstrating usage

Testing

  • 16 unit tests for runtime manager (initialization, validation, error handling)
  • 14 unit tests for configuration parser
  • 5 integration tests for TypeScript graph loading
  • 3 E2E tests for full execution flow

Documentation

  • Comprehensive TypeScript support guide (451 lines)
  • SDK usage documentation
  • Example graph with README
  • Updated .env.example with new configuration options

Testing

  • Unit tests added/updated (30 new tests)
  • Integration tests added/updated (5 new tests)
  • E2E tests added/updated (3 new tests)
  • Manual testing performed

Test results: 38 new tests, all passing

Checklist

  • Code follows project style (Ruff formatting)
  • All linting checks pass (make lint)
  • Type checking passes (make type-check) - pre-existing mypy issues in codebase
  • All tests pass for this feature (38/38 TypeScript tests passing)
  • Documentation updated (comprehensive docs added)
  • Commit messages follow Conventional Commits
  • PR title follows Conventional Commits format

Additional Notes

Backwards Compatibility

All changes are fully backwards compatible. Existing Python graphs work unchanged. TypeScript support is opt-in via configuration.

Architecture

TypeScript graphs execute in separate Node.js/Bun processes with JSON-based IPC. They share the same PostgreSQL checkpointer as Python graphs for state persistence.

Configuration

Optional JS_RUNTIME environment variable allows explicit runtime selection (auto/node/bun). Defaults to auto-detection (prefers bun over node).

PieterPel and others added 19 commits October 22, 2025 17:59
- Implement is_node_graph() to detect TS/JS graphs by file extension
- Add node_version validation following LangGraph CLI patterns
- Create AegraConfig class for loading and validating aegra.json
- Support mixed Python/TypeScript graph configurations
- Create TypeScriptRuntime class for managing Node.js processes
- Implement IPC communication via JSON streams
- Add support for both bun and node runtimes
- Create TypeScript wrapper script for graph execution
- Integrate with PostgreSQL checkpointer for state persistence
- Auto-detect and prefer bun over node when available
- Import TypeScript detection and runtime modules
- Detect graph type (Python/TypeScript) in _load_graph_registry
- Add _get_typescript_graph() method for TS graph wrappers
- Route TypeScript graphs to TS runtime manager
- Lazy-load TypeScript runtime when needed
- Maintain backward compatibility with Python graphs
- Create ts_example_agent as reference implementation
- Add simple chatbot graph with state management
- Include package.json with LangGraph dependencies
- Configure TypeScript with tsconfig.json
- Update aegra.json to register TypeScript graph
- Add node_version configuration
- Create @aegra/sdk package with full type definitions
- Implement AegraClient with Assistants/Threads/Runs APIs
- Add SSE streaming support for run execution
- Support authentication and custom headers
- Follow LangGraph SDK patterns for compatibility
- Include comprehensive README with examples
- Configure TypeScript build with declarations
- Explain TypeScript graph execution architecture
- Provide configuration reference and examples
- Document TypeScript SDK usage
- Include troubleshooting guide
- Add performance considerations
- Show migration path from LangGraph Platform
- Create unit tests for configuration parser
- Add tests for graph type detection
- Test Node.js version validation
- Add integration tests for mixed Python/TS graphs
- Create manual testing guide with examples
- Include debugging section
- Add performance testing guidance
- Add database mocking to avoid initialization requirement
- Tests now run without PostgreSQL running
- All 5 integration tests now pass
- Verify TypeScript detection and wrapper creation
- Remove manually specified versions
- Use bun add to install @langchain/langgraph@1.0.0
- Use bun add to install @langchain/core@1.0.1
- Add proper devDependencies with bun add -D
- Update SDK package.json with bun-installed versions
- Include bun-generated files
- Add astream() method required by LangGraph SDK
- Delegate to stream() method for compatibility
- Fixes: 'TypeScriptGraphWrapper' object has no attribute 'astream'
- Add **kwargs to astream() signature
- Merge kwargs into config for compatibility
- Fixes: astream() got unexpected keyword argument 'context'
- Use os.getenv('DATABASE_URL') instead of db_manager.database_url
- db_manager doesn't expose database_url as attribute
- Fixes: 'DatabaseManager' object has no attribute 'database_url'
- Change wrapper path from ts_graph_wrapper.js to .ts
- Bun can execute TypeScript files directly
- Fixes: TypeScript graph wrapper not found
- Remove callbacks, tags from config before JSON serialization
- Add _is_json_serializable() helper method
- Keep configurable dict for thread_id, run_id, etc.
- Fixes: Object of type LangchainCallbackHandler is not JSON serializable
Fixed three critical issues with TypeScript graph execution:

1. Event format (ts_graph_wrapper.ts): Removed double-wrapping of events
   - Events now stream in proper LangGraph format
   - Matches Python graph streaming behavior

2. TypeScript SDK (sdk/src/client.ts): Fixed compilation and parsing
   - Added type assertions to fix 3 compilation errors
   - Implemented proper SSE parsing (separate event: and data: lines)
   - SDK now correctly extracts event types from SSE stream

3. Backwards compatibility (langgraph_service.py): Fixed unit tests
   - Use .get("type", "python") to handle missing type field
   - Prevents KeyError in existing code and tests

All 512 tests now passing (344 unit + 147 integration + 21 manual).
TypeScript graphs work with both Python SDK and TypeScript SDK.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added comprehensive end-to-end tests for TypeScript graphs:

1. test_typescript_graph_execution_e2e: Basic TypeScript graph execution
   - Verifies assistant creation with TypeScript graph
   - Tests streaming functionality
   - Validates response format and content

2. test_typescript_graph_multiple_runs_e2e: State persistence
   - Tests multiple runs on same thread
   - Ensures state is maintained across runs

3. test_typescript_graph_with_python_graphs_e2e: Coexistence
   - Verifies TypeScript and Python graphs can coexist
   - Tests both graph types in same server instance
   - Ensures no conflicts between runtimes

All 3 tests passing. Complements existing unit (344) and integration (147)
tests for complete TypeScript support test coverage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove global singleton pattern and implement proper dependency injection:
- Runtime now managed as instance variable in LangGraphService
- Initialize during service startup if TypeScript graphs detected
- Remove unused process pool and shutdown() method

Add production-ready logging and validation:
- Replace print() with structured logging (logger.info/warning/error)
- Add input validation with early error detection
- Improve error messages with context

Performance and maintainability improvements:
- Cache runtime detection (one-time check during initialization)
- Add JS_RUNTIME environment variable (auto/node/bun)
- Optimize JSON serialization check (type-based instead of dumps)
- Add module-level constants for config filtering
- Move all imports to top of file

Testing and documentation:
- Add 16 new unit tests for error handling and validation
- Add JS_RUNTIME documentation to .env.example
- Fix TypeScript error handling with better type safety
- Update integration tests for new architecture

Results:
- 368 tests passing (360 unit + 5 integration + 3 e2e)
- Zero breaking changes
- All pre-commit hooks pass
Fix integration tests to include explicit 'type' field in graph registry
entries, matching the updated architecture that requires this field.
Remove TESTING_TYPESCRIPT.md and .cursor directories that were added
during development but shouldn't be in the repository.
@ibbybuilds ibbybuilds requested a review from Copilot October 23, 2025 17:28
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 adds proof-of-concept TypeScript/JavaScript graph support to Aegra, enabling developers to write LangGraph agents in TypeScript that execute via Node.js/Bun while sharing PostgreSQL state persistence with Python graphs.

Key Changes:

  • Added TypeScript runtime manager for executing TS/JS graphs via subprocess with IPC communication
  • Extended configuration parsing to detect and validate TypeScript graphs alongside Python graphs
  • Created comprehensive TypeScript SDK for client-side API interaction

Reviewed Changes

Copilot reviewed 27 out of 30 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/agent_server/core/ts_runtime.py Runtime manager for spawning Node.js/Bun processes and handling TypeScript graph execution
src/agent_server/core/ts_graph_wrapper.ts Node.js wrapper script that loads TS graphs and streams results back to Python
src/agent_server/core/config.py Configuration parser with TypeScript graph detection and Node.js version validation
src/agent_server/services/langgraph_service.py Extended service to support both Python and TypeScript graphs with type field in registry
sdk/src/client.ts TypeScript SDK client implementation with streaming support
sdk/src/types.ts Type definitions for Aegra API
graphs/ts_example_agent/graph.ts Example TypeScript LangGraph agent demonstrating the integration
tests/unit/test_core/test_ts_runtime.py 16 unit tests for TypeScript runtime manager
tests/unit/test_core/test_config.py 14 unit tests for configuration parser
tests/integration/test_typescript_graph.py 5 integration tests for TypeScript graph loading
tests/e2e/test_typescript/test_typescript_execution.py 3 E2E tests for full TypeScript execution flow
Comments suppressed due to low confidence (1)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +15 to +16
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

Incorrect glob pattern syntax: _.log should be *.log to match all log files. The underscore is not a wildcard character in gitignore patterns.

Suggested change
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
*.log
report.[0-9]_[0-9]_[0-9]_[0-9].json

Copilot uses AI. Check for mistakes.
@ibbybuilds
Copy link
Owner

@PieterPel Nice work on this PR! I’ll go through it in detail soon, thanks!

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 89.70588% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/agent_server/core/ts_runtime.py 89.52% 11 Missing ⚠️
src/agent_server/services/langgraph_service.py 74.35% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ibbybuilds
Copy link
Owner

@PieterPel can you please update the pr by merging main and resolving the failing CI check please.

@PieterPel PieterPel changed the title feat: TypeScript graph support feat: typescript graph support Dec 8, 2025
- Merged latest changes from upstream/main
- Resolved merge conflicts in .env.example, aegra.json, and langgraph_service.py
- Added missing 'type' field to graph registry in unit tests
- All unit and integration tests passing (653/653)
@PieterPel
Copy link
Author

@PieterPel can you please update the pr by merging main and resolving the failing CI check please.

Hi I merged and changed the PR title to full lowercase to follow the conventional commits, which caused the failing CI. Let me know if there is anything else I can do

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.

3 participants