symfonic.agent.engine¶
engine ¶
SymfonicAgent -- unified orchestrator wiring core runtime with HMS.
Provides run() and stream() entry points that transparently
hydrate memory context before LLM execution and consolidate new
memories afterward.
SymfonicAgent ¶
SymfonicAgent(
model_provider: ModelProvider,
*,
graph_preset: str = "react_loop",
config: FrameworkConfig | None = None,
graph_backend: GraphBackend | None = None,
vector_backend: VectorBackend | None = None,
embedding_provider: EmbeddingProvider | None = None,
tools: list[Any] | None = None,
sub_agents: list[Any] | None = None,
conversation_manager: Any | None = None,
orchestrator: MemoryOrchestrator | None = None,
sleep_consolidator: Any | None = None,
metrics_collector: Any | None = None,
)
High-level agent combining AgentRuntime + MemoryOrchestrator.
Minimal setup::
agent = SymfonicAgent(model_provider=my_provider)
response = await agent.run("Hello", scope=scope)
Construct the unified agent.
.. versionchanged:: 7.0
The deprecated enable_hms_prompt keyword argument has
been removed. Use FrameworkConfig(enable_hms_prompt=True)
instead — available since v6.0. Passing the removed kwarg
now raises :class:TypeError at construction time.
Source code in src/symfonic/agent/engine.py
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 | |
metrics_collector
property
¶
Return the ConversationMetricsCollector, or None if not configured.
scheduler
property
¶
Access the optional in-process scheduler.
Returns the scheduler instance if one was configured, or None.
aclose
async
¶
Release external resources held by the agent.
Closes the checkpointer factory's connection pool (psycopg pool
for the Postgres path, aiosqlite connection for the SQLite path)
and resets the _checkpointer_ready flag so a fresh astart
runs the next time the agent is used.
Idempotent -- calling aclose twice is safe; the second call
is a no-op because _checkpointer_factory is reset to None
after the first run.
v7.1.3 (Item 10.3): closes the previously-unclosed
psycopg_pool.AsyncConnectionPool opened by
PostgresCheckpointerFactory.astart. Engine re-creation in the
same process (test fixtures, hot-reload, multi-tenant routers)
would otherwise leak pools indefinitely. Pair with FastAPI
lifespan or atexit for clean shutdown.
v9.2.x (issue #27 leak fix): also releases the resources of any
child agents this parent BUILT from a SubAgentSpec -- otherwise
each declarative sub-agent's checkpointer pool leaked on parent
shutdown. Child aclose is pure resource-release + idempotent;
each is guarded so one failure can't strand the others or our own
pool. Caller-supplied pre-built SubAgent children are left
untouched (the caller owns their lifecycle).
Source code in src/symfonic/agent/engine.py
flush_background_tasks
async
¶
Await all pending background tasks (e.g. consolidation).
Call this before the event loop shuts down to ensure background work completes. Also shuts down the scheduler if one is configured. Safe to call multiple times.
v9.2.1 (review P1a): awaits only THIS agent's tasks, not the process-global set, so exiting one agent's context manager never blocks on another agent's pending consolidation.
Source code in src/symfonic/agent/engine.py
get_chat_model ¶
v7.16.0 public helper: resolve a role to its bound chat model.
Thin wrapper around resolve_model_config(role) +
self._model_provider.get_chat_model(config). Stateless
and safe to call from any thread or process — the method
reads only self._config and dispatches to the provider's
get_chat_model; it does not touch graph state, the
checkpointer, the orchestrator, or any per-turn mutable. This
is the load-bearing property for background-worker adopters
(Celery, RQ, APScheduler) who instantiate one SymfonicAgent
per process and call this from worker tasks.
Closes the v7.16-era adopter workaround
agent._model_provider.get_chat_model(agent._config.agent.model)
which bypassed the role resolver entirely and therefore missed
any role_models[role] overrides the adopter had set. The
new public method threads through resolve_model_config(role)
so role-routing flows into background workers the same way it
flows into the engine's run() entrypoint.
Default role="action" matches the v7.9.0 wired role -- the
tool-using brain LLM archetype most background workers want.
Other roles defined on FrameworkConfig.role_models resolve
through the same resolver fallback (see
resolve_model_config for the semantics: known role with
override -> returns override; unknown / unset role ->
returns self._config.agent.model).
Note: the engine's internal call sites (react node, summary,
metacognition, reflection, STM summary) continue using the
private self._model_provider reference -- they're
intra-class and already participate in role routing via the
engine's own construction wiring. This public method is for
out-of-graph consumers.
Source code in src/symfonic/agent/engine.py
get_transcript
async
¶
get_transcript(
scope: Any,
session_id: str,
*,
index: int | None = None,
time_range: tuple[datetime, datetime] | None = None,
speaker: str = "all",
limit: int | None = None,
) -> list[TranscriptMessage]
Read the verbatim conversation transcript for a thread (v7.27.0).
Surface 1 of the three-surface model (verbatim replay) -- reads
state['messages'] from the LangGraph checkpointer, NOT the lossy
episodic HMS surface. Requires a wired checkpointer
(transcript_persistence_enabled=True or ask_user_enabled=True)
AND, for durability across restart, a durable saver (Postgres or
dev_sqlite_checkpoint_path); see
docs/concepts/conversation-persistence.md.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Any
|
Tenant scope ( |
required |
session_id
|
str
|
Session identifier completing the |
required |
index
|
int | None
|
0-based ordinal over the |
None
|
time_range
|
tuple[datetime, datetime] | None
|
|
None
|
speaker
|
str
|
|
'all'
|
limit
|
int | None
|
Cap on rows returned (applied last, after index/time
filtering). |
None
|
Returns:
| Type | Description |
|---|---|
list[TranscriptMessage]
|
A list of :class: |
list[TranscriptMessage]
|
is wired, the thread is unknown, or the query matched nothing. |
Raises:
| Type | Description |
|---|---|
TranscriptUnsupportedError
|
|
Source code in src/symfonic/agent/engine.py
2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 | |
interrupt ¶
Build the state-update marker that triggers a registered interrupt.
Roadmap Item 9 surface. Returned from a tool/node body so the
graph's :class:InterruptNode picks it up on the next step and
calls LangGraph's interrupt() after the AIMessage is safely
checkpointed (mirrors the v7.1.0 ask_user topology fix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A previously-registered interrupt name. |
required |
payload
|
Any
|
A Pydantic model matching the registered
|
required |
tool_call_id
|
str | None
|
Optional tool-call id when the interrupt is
triggered from a tool; the resume path injects a
|
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The state-update dict to be returned by the calling |
dict[str, Any]
|
tool/node, e.g.:: async def my_tool(...) -> dict[str, Any]: return agent.interrupt( "approval_required", ApprovalPayload(amount=100, reason="..."), ) |
Raises:
| Type | Description |
|---|---|
SymfonicAgentError
|
|
Source code in src/symfonic/agent/engine.py
6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 | |
load_plugin ¶
Load a domain plugin into the agent.
Registers the plugin's system prompt contribution and validation hook. Multiple plugins may be loaded; their contributions are chained in registration order.
Domain tools must be provided at construction time via the
tools= parameter. If a plugin returns tools from
get_domain_tools(), this method raises SymfonicAgentError
because the AgentGraph's ToolRegistry is frozen after compile().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin
|
Any
|
Any object satisfying the BaseDomainPlugin protocol. |
required |
Raises:
| Type | Description |
|---|---|
SymfonicAgentError
|
If the plugin provides tools (which cannot
be registered after the graph has been compiled). Pass
domain tools via |
Source code in src/symfonic/agent/engine.py
on_user_correction
async
¶
on_user_correction(
*,
turn_id: str,
original_response: str,
correction_text: str,
activation_log: dict[str, Any],
scope: FrameworkTenantScope,
callbacks: Sequence[CallbackHandler] | None = None,
) -> None
Dispatch a user correction event to all handlers that support it.
Non-breaking: uses hasattr check at the call site so handlers written before v5.5 are silently skipped.
Source code in src/symfonic/agent/engine.py
register_interrupt ¶
register_interrupt(
name: str,
payload_schema: type[Any],
response_schema: type[Any],
*,
validate_response: Any = None,
cross_scope_allowed: bool = False,
) -> None
Register a named interrupt point in the graph (Roadmap Item 9).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Stable identifier (e.g. |
required |
payload_schema
|
type[Any]
|
Pydantic |
required |
response_schema
|
type[Any]
|
Pydantic |
required |
validate_response
|
Any
|
Optional cross-validator
|
None
|
cross_scope_allowed
|
bool
|
If True, the resume endpoint accepts a token issued under one scope to be redeemed under another (logs the event for audit). Default False. |
False
|
Raises:
| Type | Description |
|---|---|
SymfonicAgentError
|
|
Source code in src/symfonic/agent/engine.py
resolve_model_config ¶
v7.9.0 public helper: resolve the ModelConfig to use
for a given role.
Returns self._config.role_models[role] when set, falls
back to self._config.agent.model otherwise. Pure function
of the config; safe to call on every turn.
v7.9.0 ships "action" as the only wired role (consumed by
the react node's brain LLM at engine.py:1144-1158 via
AgentConfig injection). Other roles defined on
FrameworkConfig.role_models are reserved for v7.9.1+
wiring at the summary / critic / router / reflection /
consolidation sites. Adopters can still set them today --
the helper resolves them correctly -- but the sites that
consume them haven't been re-pointed yet. Calling this
helper for an unwired role returns the override anyway, so
adopter test code can pin the intended assignment ahead of
the v7.9.1 wiring.
Source code in src/symfonic/agent/engine.py
resume
async
¶
resume(
pause_token: str,
response: AskUserResponse,
*,
scope: FrameworkTenantScope,
callbacks: Sequence[CallbackHandler] | None = None,
) -> AsyncGenerator[StreamEvent, None]
Resume a paused agent execution from an ask_user elicitation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pause_token
|
str
|
Opaque token emitted in the original AskUserQuestionEvent. |
required |
response
|
AskUserResponse
|
The user's selections and optional free-text 'other' field. |
required |
scope
|
FrameworkTenantScope
|
Tenant scope — must match the scope that initiated the pause. |
required |
callbacks
|
Sequence[CallbackHandler] | None
|
Optional per-invocation callback handlers. |
None
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[StreamEvent, None]
|
Typed StreamEvent objects as the run continues. |
Raises:
| Type | Description |
|---|---|
SymfonicAgentError
|
If the token is invalid, expired, or already used, or if the response fails cross-validation against the original request stored in the checkpoint. |
Source code in src/symfonic/agent/engine.py
6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 | |
resume_interrupt
async
¶
resume_interrupt(
pause_token: str,
response: Any,
*,
scope: FrameworkTenantScope,
callbacks: Sequence[CallbackHandler] | None = None,
) -> AsyncGenerator[StreamEvent, None]
Resume a generic interrupt (Roadmap Item 9).
Sibling of :meth:resume (which is ask_user-specific).
The router decodes the token first, reads the name claim,
and dispatches here when name != 'ask_user'.
response is an already-validated instance of the registered
response_schema (the router validates the request body
before calling this method).
Source code in src/symfonic/agent/engine.py
6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 | |
run
async
¶
run(
query: str,
*,
attachments: Sequence[ContentPart] | None = None,
scope: FrameworkTenantScope | None = None,
callbacks: Sequence[CallbackHandler] | None = None,
session_id: str | None = None,
history: list[BaseMessage] | None = None,
is_admin: bool = False,
run_id: str | None = None,
extra_metadata: dict[str, Any] | None = None,
response_model: type[Any] | None = None,
**state_overrides: Any,
) -> AgentResponse
Execute the agent graph with automatic HMS hydration and consolidation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query text -- the canonical semantic anchor used for HMS hydration, embeddings, and tool routing. |
required |
attachments
|
Sequence[ContentPart] | None
|
Optional non-text content ( |
None
|
scope
|
FrameworkTenantScope | None
|
Tenant scope for multi-tenant isolation. |
None
|
callbacks
|
Sequence[CallbackHandler] | None
|
Optional per-invocation callback handlers. |
None
|
session_id
|
str | None
|
Optional session identifier for session tracking. |
None
|
history
|
list[BaseMessage] | None
|
Optional list of prior conversation messages (LangChain
BaseMessage instances) to prepend before the current query.
Capped at the most recent |
None
|
is_admin
|
bool
|
True to bypass budget checks (v7.0.3). |
False
|
run_id
|
str | None
|
Optional run identifier for correlation (v7.1.0). |
None
|
response_model
|
type[Any] | None
|
Optional Pydantic |
None
|
**state_overrides
|
Any
|
Arbitrary state values to merge into the graph
input (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
AgentResponse
|
AgentResponse with the final response and metadata. |
Source code in src/symfonic/agent/engine.py
4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 | |
stream
async
¶
stream(
query: str,
*,
attachments: Sequence[ContentPart] | None = None,
scope: FrameworkTenantScope | None = None,
callbacks: Sequence[CallbackHandler] | None = None,
session_id: str | None = None,
history: list[BaseMessage] | None = None,
is_admin: bool = False,
run_id: str | None = None,
extra_metadata: dict[str, Any] | None = None,
**state_overrides: Any,
) -> AsyncGenerator[StreamChunk, None]
Stream agent execution as a sequence of StreamChunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query text -- the canonical semantic anchor used for HMS hydration, embeddings, and tool routing. |
required |
attachments
|
Sequence[ContentPart] | None
|
Optional non-text content ( |
None
|
scope
|
FrameworkTenantScope | None
|
Tenant scope for multi-tenant isolation. |
None
|
callbacks
|
Sequence[CallbackHandler] | None
|
Optional per-invocation callback handlers. |
None
|
session_id
|
str | None
|
Optional session identifier for session tracking. |
None
|
history
|
list[BaseMessage] | None
|
Optional list of prior conversation messages to prepend. |
None
|
is_admin
|
bool
|
True to bypass budget checks (v7.0.3). |
False
|
run_id
|
str | None
|
Optional run identifier for correlation (v7.1.0). |
None
|
Yields: StreamChunk events with appropriate event_type progression: thinking -> acting/text_delta/tool_call/tool_result -> consolidating -> done
Source code in src/symfonic/agent/engine.py
5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 | |
stream_text
async
¶
stream_text(
query: str,
*,
attachments: Sequence[ContentPart] | None = None,
scope: FrameworkTenantScope | None = None,
callbacks: Sequence[CallbackHandler] | None = None,
session_id: str | None = None,
history: list[BaseMessage] | None = None,
) -> AsyncGenerator[str, None]
Stream only clean response text — the simplest streaming API.
Wraps stream_typed() and yields only the str payload from
TextDeltaEvent objects. All other events (lifecycle, tool calls,
activation, etc.) are silently consumed so consolidation still runs.
Extraction blocks are automatically stripped by the underlying filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query text -- the canonical semantic anchor used for HMS hydration, embeddings, and tool routing. |
required |
attachments
|
Sequence[ContentPart] | None
|
Optional non-text content ( |
None
|
scope
|
FrameworkTenantScope | None
|
Tenant scope for multi-tenant isolation. |
None
|
callbacks
|
Sequence[CallbackHandler] | None
|
Optional per-invocation callback handlers. |
None
|
session_id
|
str | None
|
Optional session identifier for session tracking. |
None
|
history
|
list[BaseMessage] | None
|
Optional list of prior conversation messages to prepend. |
None
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[str, None]
|
Clean text strings suitable for direct display in a chat UI. |
Source code in src/symfonic/agent/engine.py
stream_typed
async
¶
stream_typed(
query: str,
*,
attachments: Sequence[ContentPart] | None = None,
scope: FrameworkTenantScope | None = None,
callbacks: Sequence[CallbackHandler] | None = None,
session_id: str | None = None,
history: list[BaseMessage] | None = None,
is_admin: bool = False,
run_id: str | None = None,
extra_metadata: dict[str, Any] | None = None,
**state_overrides: Any,
) -> AsyncGenerator[StreamEvent, None]
Stream agent execution as typed StreamEvent objects.
Identical hydration, scope injection, and HMS prompt composition
as stream(), but yields typed StreamEvent instances
(TextDeltaEvent, ToolCallStartEvent, ThinkingDeltaEvent, etc.)
instead of StreamChunk wrappers. Designed for library
consumers that want structured event access without parsing raw
LangGraph dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query text -- the canonical semantic anchor used for HMS hydration, embeddings, and tool routing. |
required |
attachments
|
Sequence[ContentPart] | None
|
Optional non-text content ( |
None
|
scope
|
FrameworkTenantScope | None
|
Tenant scope for multi-tenant isolation. |
None
|
callbacks
|
Sequence[CallbackHandler] | None
|
Optional per-invocation callback handlers. |
None
|
session_id
|
str | None
|
Optional session identifier for session tracking. |
None
|
history
|
list[BaseMessage] | None
|
Optional list of prior conversation messages to prepend. |
None
|
is_admin
|
bool
|
True to bypass budget checks (v7.0.3). |
False
|
run_id
|
str | None
|
Optional run identifier for correlation (v7.1.0). |
None
|
**state_overrides
|
Any
|
Arbitrary state values to merge into the graph
input (e.g. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[StreamEvent, None]
|
Typed StreamEvent objects from the EventTranspiler. |
Source code in src/symfonic/agent/engine.py
5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 | |
validate_action
async
¶
Check all loaded plugins' guardrails for an action.
Iterates every registered plugin and calls its
validate_state_transition hook. Returns False immediately if
any plugin rejects the action. Plugin errors are non-fatal and
default to allowing the action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Name of the action/tool being attempted. |
required |
context
|
dict[str, Any]
|
Current execution context (tenant, params, etc.) |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all plugins allow the action, False if any block it. |