Spaces:
Running
Running
Commit
·
9de209d
1
Parent(s):
2c820a4
fixing tracing
Browse files- agent/core/session.py +0 -14
- agent/main.py +13 -0
- eval/hf_agent_connector.py +3 -0
- eval/solvers.py +7 -0
agent/core/session.py
CHANGED
|
@@ -1,13 +1,9 @@
|
|
| 1 |
import asyncio
|
| 2 |
-
import os
|
| 3 |
import uuid
|
| 4 |
from dataclasses import dataclass
|
| 5 |
from enum import Enum
|
| 6 |
from typing import Any, Optional
|
| 7 |
|
| 8 |
-
import litellm
|
| 9 |
-
from lmnr import Laminar, LaminarLiteLLMCallback
|
| 10 |
-
|
| 11 |
from agent.config import Config
|
| 12 |
from agent.context_manager.manager import ContextManager
|
| 13 |
|
|
@@ -38,16 +34,6 @@ class Session:
|
|
| 38 |
event_queue: asyncio.Queue,
|
| 39 |
config: Config | None = None,
|
| 40 |
):
|
| 41 |
-
# Initialize Laminar if API key is present
|
| 42 |
-
lmnr_api_key = os.environ.get("LMNR_API_KEY")
|
| 43 |
-
if lmnr_api_key:
|
| 44 |
-
try:
|
| 45 |
-
Laminar.initialize(project_api_key=lmnr_api_key)
|
| 46 |
-
litellm.callbacks = [LaminarLiteLLMCallback()]
|
| 47 |
-
print("✅ Laminar initialized")
|
| 48 |
-
except Exception as e:
|
| 49 |
-
print(f"⚠️ Failed to initialize Laminar: {e}")
|
| 50 |
-
|
| 51 |
self.context_manager = ContextManager()
|
| 52 |
self.event_queue = event_queue
|
| 53 |
self.session_id = str(uuid.uuid4())
|
|
|
|
| 1 |
import asyncio
|
|
|
|
| 2 |
import uuid
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from enum import Enum
|
| 5 |
from typing import Any, Optional
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
from agent.config import Config
|
| 8 |
from agent.context_manager.manager import ContextManager
|
| 9 |
|
|
|
|
| 34 |
event_queue: asyncio.Queue,
|
| 35 |
config: Config | None = None,
|
| 36 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
self.context_manager = ContextManager()
|
| 38 |
self.event_queue = event_queue
|
| 39 |
self.session_id = str(uuid.uuid4())
|
agent/main.py
CHANGED
|
@@ -3,10 +3,14 @@ Interactive CLI chat with the agent
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import asyncio
|
|
|
|
| 6 |
from dataclasses import dataclass
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Any, Optional
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
from agent.config import load_config
|
| 11 |
from agent.core.agent_loop import submission_loop
|
| 12 |
from agent.core.session import OpType
|
|
@@ -94,6 +98,15 @@ async def main():
|
|
| 94 |
print("=" * 60)
|
| 95 |
print("Type your messages below. Type 'exit', 'quit', or '/quit' to end.\n")
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# Create queues for communication
|
| 98 |
submission_queue = asyncio.Queue()
|
| 99 |
event_queue = asyncio.Queue()
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import asyncio
|
| 6 |
+
import os
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Any, Optional
|
| 10 |
|
| 11 |
+
import litellm
|
| 12 |
+
from lmnr import Laminar, LaminarLiteLLMCallback
|
| 13 |
+
|
| 14 |
from agent.config import load_config
|
| 15 |
from agent.core.agent_loop import submission_loop
|
| 16 |
from agent.core.session import OpType
|
|
|
|
| 98 |
print("=" * 60)
|
| 99 |
print("Type your messages below. Type 'exit', 'quit', or '/quit' to end.\n")
|
| 100 |
|
| 101 |
+
lmnr_api_key = os.environ.get("LMNR_API_KEY")
|
| 102 |
+
if lmnr_api_key:
|
| 103 |
+
try:
|
| 104 |
+
Laminar.initialize(project_api_key=lmnr_api_key)
|
| 105 |
+
litellm.callbacks = [LaminarLiteLLMCallback()]
|
| 106 |
+
print("✅ Laminar initialized")
|
| 107 |
+
except Exception as e:
|
| 108 |
+
print(f"⚠️ Failed to initialize Laminar: {e}")
|
| 109 |
+
|
| 110 |
# Create queues for communication
|
| 111 |
submission_queue = asyncio.Queue()
|
| 112 |
event_queue = asyncio.Queue()
|
eval/hf_agent_connector.py
CHANGED
|
@@ -5,6 +5,8 @@ import sys
|
|
| 5 |
from pathlib import Path
|
| 6 |
from typing import Any
|
| 7 |
|
|
|
|
|
|
|
| 8 |
from agent.config import Config, load_config
|
| 9 |
from agent.core.agent_loop import Handlers
|
| 10 |
from agent.core.session import Session
|
|
@@ -38,6 +40,7 @@ class AgentResponseGenerator:
|
|
| 38 |
"""Expose the agent model name for downstream logging."""
|
| 39 |
return self.config.model_name
|
| 40 |
|
|
|
|
| 41 |
async def run(self, prompt: str) -> str:
|
| 42 |
"""
|
| 43 |
Execute the agent loop for a single prompt and return the assistant reply.
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
from typing import Any
|
| 7 |
|
| 8 |
+
from lmnr import observe
|
| 9 |
+
|
| 10 |
from agent.config import Config, load_config
|
| 11 |
from agent.core.agent_loop import Handlers
|
| 12 |
from agent.core.session import Session
|
|
|
|
| 40 |
"""Expose the agent model name for downstream logging."""
|
| 41 |
return self.config.model_name
|
| 42 |
|
| 43 |
+
@observe(name="eval_run")
|
| 44 |
async def run(self, prompt: str) -> str:
|
| 45 |
"""
|
| 46 |
Execute the agent loop for a single prompt and return the assistant reply.
|
eval/solvers.py
CHANGED
|
@@ -10,9 +10,11 @@ import os
|
|
| 10 |
import tempfile
|
| 11 |
from typing import Callable, Dict, List, Sequence
|
| 12 |
|
|
|
|
| 13 |
from inspect_ai.model import ChatMessageAssistant, ModelOutput
|
| 14 |
from inspect_ai.solver import Solver, solver
|
| 15 |
from inspect_ai.solver._task_state import TaskState
|
|
|
|
| 16 |
|
| 17 |
from eval.hf_agent_connector import AgentResponseGenerator
|
| 18 |
|
|
@@ -37,6 +39,11 @@ def hf_agent(
|
|
| 37 |
config_path: str = "agent/config_mcp_example.json",
|
| 38 |
max_iterations: int = 10,
|
| 39 |
) -> Solver:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
runner = AgentResponseGenerator(
|
| 41 |
config_path=config_path,
|
| 42 |
max_iterations=max_iterations,
|
|
|
|
| 10 |
import tempfile
|
| 11 |
from typing import Callable, Dict, List, Sequence
|
| 12 |
|
| 13 |
+
import litellm
|
| 14 |
from inspect_ai.model import ChatMessageAssistant, ModelOutput
|
| 15 |
from inspect_ai.solver import Solver, solver
|
| 16 |
from inspect_ai.solver._task_state import TaskState
|
| 17 |
+
from lmnr import Laminar, LaminarLiteLLMCallback
|
| 18 |
|
| 19 |
from eval.hf_agent_connector import AgentResponseGenerator
|
| 20 |
|
|
|
|
| 39 |
config_path: str = "agent/config_mcp_example.json",
|
| 40 |
max_iterations: int = 10,
|
| 41 |
) -> Solver:
|
| 42 |
+
# init lmnr for observability
|
| 43 |
+
Laminar.initialize(project_api_key=os.environ.get("LMNR_API_KEY"))
|
| 44 |
+
litellm.callbacks = [LaminarLiteLLMCallback()]
|
| 45 |
+
print("✅ Laminar initialized")
|
| 46 |
+
|
| 47 |
runner = AgentResponseGenerator(
|
| 48 |
config_path=config_path,
|
| 49 |
max_iterations=max_iterations,
|