File size: 901 Bytes
dd8e099
f9a89db
 
2a3656e
f9a89db
 
 
 
 
2a3656e
f9a89db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# agent_factory.py
from smolagents import CodeAgent, InferenceClientModel

from config import AUTHORIZED_IMPORTS, CUSTOM_ROLE_CONVERSIONS, MODEL_ID
from tools import build_tools


# One model per process (generation is stateless)
model = InferenceClientModel(
    model_id=MODEL_ID,
    custom_role_conversions=CUSTOM_ROLE_CONVERSIONS,
)

# Build tools once; browser/HTTP sessions are reused across requests
_web_tools, _document_inspection_tool, _visualizer = build_tools(model)


def get_model():
    return model


def get_document_inspection_tool():
    return _document_inspection_tool


def create_agent():
    """Return a fresh CodeAgent for each new user session."""
    return CodeAgent(
        model=model,
        tools=[_visualizer] + _web_tools,
        max_steps=10,
        verbosity_level=1,
        additional_authorized_imports=AUTHORIZED_IMPORTS,
        planning_interval=4,
    )