Spaces:
Paused

flowmarg / agent /harness_agent.py
akash
Deploy to Hugging Face (source code only, no binary files)
2379054
Raw History Blame Contribute Delete
1.13 kB
"""
Agent factory: always prefer LangChain if available, else fallback to local.
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from agent.local_agent import LocalEngineeringAgent, get_or_create_agent as get_local_agent
try:
from agent.langchain_agent import create_langchain_agent
LANGCHAIN_AVAILABLE = True
except Exception:
LANGCHAIN_AVAILABLE = False
def get_or_create_agent(session_state):
"""Return a LangChain agent if available, else fallback to local."""
if LANGCHAIN_AVAILABLE:
try:
# Check if we have Gemini API key
import os
if os.environ.get("GEMINI_API_KEY"):
# Create or retrieve from session state
if 'langchain_agent' not in session_state:
session_state.langchain_agent = create_langchain_agent(session_state)
return session_state.langchain_agent
except Exception:
pass
# Fallback to local
return get_local_agent(session_state)
# Back-compat alias
HarnessAgent = LocalEngineeringAgent