mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
feat(agents): track permission and compaction events
This commit is contained in:
parent
ea3d0a6463
commit
53691f9c51
4 changed files with 10 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ from langchain_core.tools import BaseTool
|
||||||
from langgraph.types import interrupt
|
from langgraph.types import interrupt
|
||||||
|
|
||||||
from app.agents.new_chat.permissions import Rule
|
from app.agents.new_chat.permissions import Rule
|
||||||
|
from app.observability import metrics as ot_metrics
|
||||||
from app.observability import otel as ot
|
from app.observability import otel as ot
|
||||||
|
|
||||||
from .decision import normalize_permission_decision
|
from .decision import normalize_permission_decision
|
||||||
|
|
@ -52,6 +53,8 @@ def request_permission_decision(
|
||||||
),
|
),
|
||||||
ot.interrupt_span(interrupt_type=PERMISSION_ASK_INTERRUPT_TYPE),
|
ot.interrupt_span(interrupt_type=PERMISSION_ASK_INTERRUPT_TYPE),
|
||||||
):
|
):
|
||||||
|
ot_metrics.record_permission_ask(permission=tool_name)
|
||||||
|
ot_metrics.record_interrupt(interrupt_type=PERMISSION_ASK_INTERRUPT_TYPE)
|
||||||
decision = interrupt(payload)
|
decision = interrupt(payload)
|
||||||
return normalize_permission_decision(decision)
|
return normalize_permission_decision(decision)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ from deepagents.middleware.summarization import (
|
||||||
)
|
)
|
||||||
from langchain_core.messages import SystemMessage
|
from langchain_core.messages import SystemMessage
|
||||||
|
|
||||||
|
from app.observability import metrics as ot_metrics
|
||||||
from app.observability import otel as ot
|
from app.observability import otel as ot
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
@ -178,6 +179,7 @@ class SurfSenseCompactionMiddleware(SummarizationMiddleware):
|
||||||
messages_in=len(conversation_messages),
|
messages_in=len(conversation_messages),
|
||||||
extra={"compaction.cutoff_index": int(cutoff_index)},
|
extra={"compaction.cutoff_index": int(cutoff_index)},
|
||||||
):
|
):
|
||||||
|
ot_metrics.record_compaction_run(reason="auto")
|
||||||
messages_to_summarize, preserved_messages = super()._partition_messages(
|
messages_to_summarize, preserved_messages = super()._partition_messages(
|
||||||
conversation_messages, cutoff_index
|
conversation_messages, cutoff_index
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ from langgraph.config import get_config
|
||||||
from langgraph.runtime import Runtime
|
from langgraph.runtime import Runtime
|
||||||
from langgraph.types import interrupt
|
from langgraph.types import interrupt
|
||||||
|
|
||||||
|
from app.observability import metrics as ot_metrics
|
||||||
from app.observability import otel as ot
|
from app.observability import otel as ot
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -195,6 +196,7 @@ class DoomLoopMiddleware(AgentMiddleware[AgentState[ResponseT], ContextT, Respon
|
||||||
"interrupt.tool": (action or {}).get("tool", "<unknown>"),
|
"interrupt.tool": (action or {}).get("tool", "<unknown>"),
|
||||||
},
|
},
|
||||||
):
|
):
|
||||||
|
ot_metrics.record_interrupt(interrupt_type="permission_ask")
|
||||||
decision = interrupt(
|
decision = interrupt(
|
||||||
{
|
{
|
||||||
"type": "permission_ask",
|
"type": "permission_ask",
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ from app.agents.new_chat.permissions import (
|
||||||
aggregate_action,
|
aggregate_action,
|
||||||
evaluate_many,
|
evaluate_many,
|
||||||
)
|
)
|
||||||
|
from app.observability import metrics as ot_metrics
|
||||||
from app.observability import otel as ot
|
from app.observability import otel as ot
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -284,6 +285,8 @@ class PermissionMiddleware(AgentMiddleware): # type: ignore[type-arg]
|
||||||
),
|
),
|
||||||
ot.interrupt_span(interrupt_type="permission_ask"),
|
ot.interrupt_span(interrupt_type="permission_ask"),
|
||||||
):
|
):
|
||||||
|
ot_metrics.record_permission_ask(permission=tool_name)
|
||||||
|
ot_metrics.record_interrupt(interrupt_type="permission_ask")
|
||||||
decision = interrupt(payload)
|
decision = interrupt(payload)
|
||||||
return _normalize_permission_decision(decision)
|
return _normalize_permission_decision(decision)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue