Download agent/harness_agent.py from Surajnitp/flowmarg: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/Surajnitp/flowmarg/resolve/main/agent/harness_agent.py
- Command line
-
hf download hf://spaces/Surajnitp/flowmarg/agent/harness_agent.py
-
curl -L -o harness_agent.py https://huggingface.co/spaces/Surajnitp/flowmarg/resolve/main/agent/harness_agent.py
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 | |