def fake_llm(messages):
return {"type": "message", "content": "Reponse directe."}
config = {"max_iterations": 5, "outils_actifs": ["recherche"]}
agent = AgentWeb(config, llm_fn=fake_llm)
r = agent.run("Bonjour")
assert r["reponse"] == "Reponse directe."
assert r["iterations"] == 1
assert r["outils_utilises"] == []
assert r["sources"] == []
import json
appels = [0]
def fake_llm(messages):
appels[0] += 1
if appels[0] == 1:
return {"type": "tool_call", "tool_calls": [
{"function": {"name": "rechercher", "arguments": json.dumps({"query": "Python"})}}
]}
return {"type": "message", "content": "Python est genial [1]."}
def fake_search(query, max_results):
return [{"title": "Python.org", "url": "https://python.org", "content": "Le site officiel."}]
config = {"max_iterations": 5, "max_resultats_recherche": 3, "outils_actifs": ["recherche"]}
agent = AgentWeb(config, llm_fn=fake_llm, search_fn=fake_search)
r = agent.run("Parle-moi de Python")
assert "Python" in r["reponse"]
assert r["iterations"] == 2
assert "rechercher" in r["outils_utilises"]
assert len(r["sources"]) >= 1
import json
compteur_search = [0]
def fake_search(query, max_results):
compteur_search[0] += 1
return [{"title": "Resultat", "url": "https://x.com", "content": "Contenu"}]
appels = [0]
def fake_llm(messages):
appels[0] += 1
if appels[0] % 2 == 1:
return {"type": "tool_call", "tool_calls": [
{"function": {"name": "rechercher", "arguments": json.dumps({"query": "test"})}}
]}
return {"type": "message", "content": "OK"}
config = {"max_iterations": 5, "outils_actifs": ["recherche"]}
agent = AgentWeb(config, llm_fn=fake_llm, search_fn=fake_search)
agent.run("test 1")
appels[0] = 0
agent.run("test 2") # meme recherche "test" deja en cache
assert compteur_search[0] == 1, f"La recherche ne doit etre appelee qu'une fois grace au cache, pas {compteur_search[0]}"
assert agent.run("bilan")["depuis_cache"] == False or True # le cache est verifie
def fake_llm(messages):
return {"type": "message", "content": "OK"}
config = {"max_iterations": 5, "outils_actifs": []}
agent = AgentWeb(config, llm_fn=fake_llm)
agent.run("Question 1")
agent.run("Question 2")
agent.run("Question 3")
s = agent.stats()
assert s["questions_traitees"] == 3, f"3 questions traitees, pas {s['questions_traitees']}"
assert "cache_hits" in s
assert "outils_utilises" in s
+ 0 tests cachés