fix: retain planning feedback and add acceptance probes
This commit is contained in:
@@ -26,9 +26,12 @@ class BrainService:
|
||||
with open(path,'xb') as f:os.chmod(path,0o600);f.write(data);f.flush();os.fsync(f.fileno())
|
||||
except FileExistsError:pass
|
||||
result.update(image_path=str(path.resolve()),sha256=digest);return result
|
||||
def _record(self,capability,goal,raw,result,observation=None):
|
||||
def _record(self,capability,goal,raw,result,observation=None,prompt=None):
|
||||
path=self.records/(uuid.uuid4().hex+'.json')
|
||||
body=dict(schema_version=1,capability=capability,recorded_at_ns=time.time_ns(),model_version=self.backend.model_version,prompt_version=PROMPT_VERSION,input=goal,observation=observation,raw_output=raw,result=result)
|
||||
body['prompt_provenance']=({'status':'captured','sha256':hashlib.sha256(prompt.encode('utf-8')).hexdigest(),
|
||||
'template_sha256':hashlib.sha256(PLANNER_RULES.encode('utf-8')).hexdigest()} if prompt is not None and capability=='plan'
|
||||
else {'status':'missing','reason':'no captured inference prompt for this record'})
|
||||
with open(path,'x',encoding='utf-8') as f:
|
||||
os.chmod(path,0o600);f.write(canonical(body));f.flush();os.fsync(f.fileno())
|
||||
return str(path.resolve())
|
||||
@@ -44,7 +47,7 @@ class BrainService:
|
||||
if not isinstance(raw,str) or len(raw.encode())>262144:raise InferenceError('OUTPUT_TOO_LARGE')
|
||||
return raw
|
||||
def plan(self,goal,cancel=None):
|
||||
raw=''
|
||||
raw='';prompt=None
|
||||
try:
|
||||
if not isinstance(goal.get('instruction'),str) or not 0<len(goal['instruction'])<=1000 or not goal['instruction'].strip():raise InferenceError('INVALID_INPUT')
|
||||
for key in ('task_revision','planning_generation'):
|
||||
@@ -66,7 +69,8 @@ class BrainService:
|
||||
else:
|
||||
if len(extracted['items'])!=1:raise InferenceError('SEMANTIC_MISMATCH')
|
||||
known={**extracted['items'][0],'destination':extracted['destination'],**known}
|
||||
raw=self._call('plan',goal,PLANNER_RULES+'\nINPUT: '+canonical(goal),cancel)
|
||||
prompt=PLANNER_RULES+'\nINPUT: '+canonical(goal)
|
||||
raw=self._call('plan',goal,prompt,cancel)
|
||||
try:data=strict_json(raw)
|
||||
except (ValueError,TypeError):raise InferenceError('PARSE_ERROR')
|
||||
if isinstance(data,dict) and set(data)=={'missing_information'}:
|
||||
@@ -88,7 +92,7 @@ class BrainService:
|
||||
if any(expected.get(k)!=v for k,v in known.items()):raise InferenceError('SEMANTIC_MISMATCH')
|
||||
result=dict(status='PLAN_READY',plan=plan,error_code='')
|
||||
except (InferenceError,ApiError,KeyError,TypeError,ValueError,AttributeError) as ex:result=dict(status='FAILED',error_code=getattr(ex,'code','INVALID_INPUT'),message=str(ex))
|
||||
result['record_ref']=self._record('plan',goal,raw,result)
|
||||
result['record_ref']=self._record('plan',goal,raw,result,prompt=prompt)
|
||||
return result
|
||||
def shelf(self,goal,observation,now_ns,max_age_ns=2_000_000_000,cancel=None):
|
||||
raw='';obs=None
|
||||
|
||||
Reference in New Issue
Block a user