ExamplescriptintermediateRunnableresearch-brief
Interactive Agent
Runnable example (intermediate) for script using docling, openai.
Key Facts
- Level
- intermediate
- Runtime
- Python • OpenAI API
- Pattern
- Context-backed research with explicit evidence
- Interaction
- Live sandbox • Script
- Updated
- 14 March 2026
Navigate this example
Library
Browse examplesReopen the wider library to compare adjacent patterns and linked learning paths.Interaction
Run sandbox nowTry the interaction directly in this example’s guided sandbox surface.Source
Open full sourceRead the real implementation, highlighted checkpoints, and runtime requirements.MCP
Call via MCPUse the same resource inside agents, deterministic exports, and MCP setup flows.
Linked principles
5-interactive-agent.py
python
from tools import SearchAgent
def main():
"""Run interactive terminal agent."""
agent = SearchAgent()
print("=" * 70)
print("Research Assistant for Dutch Government Organizations")
print("=" * 70)
print("\nType 'quit' or 'exit' to end the conversation.")
print("Type 'reset' to clear conversation history.\n")
while True:
try:
query = input("You: ").strip()
if not query:
continue
if query.lower() in ["quit", "exit", "q"]:
print("\nGoodbye!")
break
if query.lower() == "reset":
agent.reset()
print("Conversation history cleared.\n")
continue
print()
result = agent.ask(query)
print(f"\nAssistant: {result.answer}\n")
if result.citations:
print("Citations:")
for citation in result.citations:
source = citation.url or f"Section {citation.section}"
print(f" {source}: {citation.text[:100]}...")
print()
except KeyboardInterrupt:
print("\n\nGoodbye!")
break
except Exception as e:
print(f"\nError: {e}\n")
if __name__ == "__main__":
main()
Related principles
- P4trustApply progressive disclosure to system agencyProvide the minimum information necessary by default, while enabling users to inspect additional detail when confidence, understanding, or intervention is required.Open principle →
- P6visibilityExpose meaningful operational state, not internal complexityPresent the state of the system in language and structures that are relevant to the user, rather than exposing low-level internals that do not support action or understanding.Open principle →
- P7trustEstablish trust through inspectabilityUsers should be able to examine how a result was produced when confidence, accountability, or decision quality is important.Open principle →
- P9orchestrationRepresent delegated work as a system, not merely as a conversationWhere work involves multiple steps, agents, dependencies, or concurrent activities, it should be represented as a structured system rather than solely as a message stream.Open principle →