Skip to content

Commit 4ce835e

Browse files
fix: agent history parameter and conditional logfire instrumentation
- Fixed run_agent Modal function passing max_turns where history was expected - Added history parameter to Modal spawn call for conversation continuity - Made logfire instrumentation conditional on token being set (cleaner local dev)
1 parent 128408d commit 4ce835e

6 files changed

Lines changed: 32 additions & 15 deletions

File tree

docs/src/app/globals.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ code {
103103

104104
/* Agent response content */
105105
.response-content {
106-
font-family: var(--font-inter), -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
107-
font-size: 15px;
108-
line-height: 1.7;
106+
font-family: "Instrument Serif", Georgia, "Times New Roman", serif;
107+
font-size: 17px;
108+
line-height: 1.75;
109109
color: #1e293b;
110110
-webkit-font-smoothing: antialiased;
111111
}
@@ -121,14 +121,15 @@ code {
121121
.response-content h1,
122122
.response-content h2,
123123
.response-content h3 {
124+
font-family: var(--font-inter), -apple-system, sans-serif;
124125
font-weight: 600;
125126
color: #0f172a;
126127
margin-top: 1.5em;
127128
margin-bottom: 0.5em;
128129
line-height: 1.3;
129130
}
130131
.response-content h1 {
131-
font-size: 1.375em;
132+
font-size: 1.25em;
132133
}
133134
.response-content h2 {
134135
font-size: 1.125em;
@@ -185,6 +186,7 @@ code {
185186
width: 100%;
186187
border-collapse: collapse;
187188
margin: 1em 0;
189+
font-family: var(--font-inter), -apple-system, sans-serif;
188190
font-size: 14px;
189191
}
190192
.response-content th {

docs/src/components/policy-chat.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,11 @@ export function PolicyChat() {
561561
: "bg-white border border-[var(--color-border)]"
562562
}`}>
563563
<div
564-
className="response-content font-[family-name:var(--font-inter)]"
564+
className="response-content"
565565
style={{
566-
fontSize: '15px',
567-
lineHeight: 1.7,
566+
fontFamily: '"Instrument Serif", Georgia, serif',
567+
fontSize: '17px',
568+
lineHeight: 1.75,
568569
}}
569570
>
570571
<ReactMarkdown remarkPlugins={[remarkBreaks, remarkGfm]}>

src/policyengine_api/agent_sandbox.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import re
55
import time
6-
from typing import Any, Callable
6+
from typing import Callable
77

88
import anthropic
99
import modal
@@ -469,10 +469,17 @@ def run_agent(
469469
question: str,
470470
api_base_url: str = "https://v2.api.policyengine.org",
471471
call_id: str = "",
472+
history: list[dict] | None = None,
472473
max_turns: int = 30,
473474
) -> dict:
474475
"""Run agentic loop to answer a policy question (Modal wrapper)."""
475-
return _run_agent_impl(question, api_base_url, call_id, max_turns)
476+
return _run_agent_impl(
477+
question,
478+
api_base_url,
479+
call_id,
480+
history=history,
481+
max_turns=max_turns,
482+
)
476483

477484

478485
if __name__ == "__main__":

src/policyengine_api/api/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ async def run_agent(request: RunRequest) -> RunResponse:
127127
import modal
128128

129129
run_fn = modal.Function.from_name("policyengine-sandbox", "run_agent")
130-
call = run_fn.spawn(request.question, api_base_url, call_id)
130+
history_dicts = [{"role": m.role, "content": m.content} for m in request.history]
131+
call = run_fn.spawn(request.question, api_base_url, call_id, history_dicts)
131132

132133
_calls[call_id] = {
133134
"call": call,

src/policyengine_api/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
console = Console()
1818

1919
# Configure Logfire (only if token is set)
20-
if settings.logfire_token:
20+
_logfire_enabled = bool(settings.logfire_token)
21+
if _logfire_enabled:
2122

2223
def _scrubbing_callback(m: logfire.ScrubMatch):
2324
"""Allow 'session' through for Claude stream debugging."""
@@ -67,8 +68,9 @@ async def lifespan(app: FastAPI):
6768
allow_headers=["*"],
6869
)
6970

70-
# Instrument FastAPI with Logfire
71-
logfire.instrument_fastapi(app)
71+
# Instrument FastAPI with Logfire (only if configured)
72+
if _logfire_enabled:
73+
logfire.instrument_fastapi(app)
7274

7375
app.include_router(api_router)
7476

src/policyengine_api/services/database.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import logfire
21
from sqlmodel import Session, create_engine
32

43
from policyengine_api.config.settings import settings
54

65
engine = create_engine(settings.database_url, echo=settings.debug)
7-
logfire.instrument_sqlalchemy(engine=engine)
6+
7+
# Only instrument with logfire if configured
8+
if settings.logfire_token:
9+
import logfire
10+
11+
logfire.instrument_sqlalchemy(engine=engine)
812

913

1014
def get_session():

0 commit comments

Comments
 (0)