Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/694057b6-101c-8007-9a65-c40578c7252d
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===== - The request accumulates output text whenever TextDelta events arrive. ===== * On any terminal state (COMPLETED, FAILED, CANCELED), get_result() returns: - text: the full accumulated output so far (possibly empty) - signals: any recorded exit signals - failure details if applicable Even tool failures and restarts must preserve accumulated output until get_result() is called. ===== <syntaxhighlight lang="python">async def run_request(req: RequestRecord) -> None: ===== try: # Build initial conversation with BIOS + caller system + user req.conversation = build_initial_conversation(req) while True: payload = build_chat_payload(req.conversation, req.params, tools=req.all_tools) stream = transport.stream_chat(payload) # Per-stream scratch assistant_text = "" structured_tool_calls = None async for event in stream: req.last_stream_byte_at = now_monotonic() # any bytes after headers count as progress if event.type == "TextDelta": assistant_text += event.text req.output += event.text loop_detector.feed(event.text) if loop_detector.triggered(): req.fail("repeated_line_loop") return elif event.type == "AssistantMessageFinal": structured_tool_calls = extract_tool_calls(event.message_obj) # Some servers finalize here; continue to StreamDone elif event.type == "ServerError": req.fail("unknown_error", detail=str(event.error)) return elif event.type == "StreamDone": break # Tool detection: structured first, then fallback normal_calls, exit_calls, err = partition_structured_calls(structured_tool_calls) if err: req.fail("tool_parse_error", detail=err) return record_exit_calls(req, exit_calls) if normal_calls: if req.tool_iters_remaining <= 0: req.fail("tool_execution_error", detail="tool budget exhausted") return # Append assistant tool-call message (NORMAL ONLY), execute tools, append tool results ok, err = await execute_normal_tools(req, normal_calls) if not ok: req.fail("tool_execution_error", detail=err) return req.tool_iters_remaining -= len(normal_calls) req.conversation = rebuild_conversation_with_new_bios(req) continue # loop back to generate more # No structured normal calls; try fallback parsing on the recent output fb = try_fallback_parse_tool_call(assistant_text) if fb: if fb.name in exit_tool_names: record_exit_signal(req, fb) # optional: strip directive from output req.output = strip_fallback_directive(req.output, fb) # no continuation mandated; allow model to finish naturally # (if you want continuation behavior, keep it explicit and tested) elif fb.name in normal_tool_names: # strip directive from output, run normal tool loop, then continue req.output = strip_fallback_directive(req.output, fb) ok, err = await execute_normal_tools(req, [fb]) if not ok: req.fail("tool_execution_error", detail=err) return req.tool_iters_remaining -= 1 req.conversation = rebuild_conversation_with_new_bios(req) continue else: req.fail("tool_parse_error", detail="unknown fallback tool") return # Otherwise: no tools detected -> completion req.complete(finish_reason=deduce_finish_reason(req.params, req.output)) return except asyncio.CancelledError: req.cancel() raise except Exception as e: req.fail("unknown_error", detail=str(e)) finally: release_slot(req) </syntaxhighlight> If you want to proceed, the next appendices that are most useful for implementation and testing are: * Appendix I: Restart policy and crash-loop behavior (explicit algorithm) * Appendix J: Liveness probing details (/proc/<pid>/stat CPU time delta) * Appendix L: Test plan and stub-server fixtures (test matrix)
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)