mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-05-23 21:06:39 +00:00
* Add survey profile DB, parser, and background refiner Co-authored-by: nic <nicsins@users.noreply.github.com> * Block external survey domains unless allowlisted Co-authored-by: nic <nicsins@users.noreply.github.com> * Add persona creation tool for survey personas Co-authored-by: nic <nicsins@users.noreply.github.com> * Add local survey demo and documentation Co-authored-by: nic <nicsins@users.noreply.github.com> * Add profile update tool and email env fallback Co-authored-by: nic <nicsins@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: nic <nicsins@users.noreply.github.com>
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import json
|
|
|
|
from python.helpers.tool import Tool, Response
|
|
from python.surveys.db import SurveyDB
|
|
from python.surveys.schemas import UserProfile
|
|
from python.surveys.profile_refiner import _deep_merge
|
|
|
|
|
|
class ProfileUpdate(Tool):
|
|
async def execute(
|
|
self,
|
|
profile_id: str = "default",
|
|
patch_json: str = "",
|
|
persona_id: str = "",
|
|
**kwargs,
|
|
):
|
|
"""
|
|
Update (deep-merge) the structured survey profile stored in SQLite.
|
|
|
|
- profile_id: profile key (default "default")
|
|
- patch_json: JSON object to deep-merge into profile.data
|
|
- persona_id: optional persona association
|
|
"""
|
|
if not patch_json:
|
|
return Response(
|
|
message="patch_json is required and must be a JSON object.",
|
|
break_loop=False,
|
|
)
|
|
|
|
try:
|
|
patch = json.loads(patch_json)
|
|
except Exception as e:
|
|
return Response(message=f"Invalid patch_json: {e}", break_loop=False)
|
|
|
|
if not isinstance(patch, dict):
|
|
return Response(message="patch_json must be a JSON object.", break_loop=False)
|
|
|
|
db = SurveyDB.for_agent(self.agent)
|
|
try:
|
|
profile = db.get_profile(profile_id) or UserProfile(
|
|
id=profile_id, persona_id=(persona_id or None), data={}
|
|
)
|
|
if persona_id:
|
|
profile.persona_id = persona_id
|
|
profile.data = _deep_merge(profile.data or {}, patch)
|
|
db.upsert_profile(profile)
|
|
return Response(
|
|
message=json.dumps(
|
|
{"profile_id": profile.id, "updated_keys": sorted(patch.keys())},
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
),
|
|
break_loop=False,
|
|
)
|
|
finally:
|
|
db.close()
|
|
|