"""my-agent: an agent without a server. It finds a service on EuKollab, tries the candidates and uses the best one. Written for ekl-provider-adapter 0.4.0. Run it: pip install -r requirements.txt # .env holds EKL_AGENT_CREDENTIAL, which ekl new agent wrote (or: ekl agent take-part ) python agent.py It needs no public address: it only connects out. """ from typing import Any from dotenv import load_dotenv from ekl_provider_adapter import Agent, NoProvider, NotAllowed # .env holds the agent key and settings `ekl` wrote; your hosting's environment takes precedence over it. load_dotenv() agent = Agent.from_env() @agent.on_start def find_and_use() -> None: try: choice = agent.choose( "validate EU VAT numbers", # TODO: what you need, in a few words sample={"vat_number": "DE123456789"}, # TODO: your own test case check=lambda out: out.get("valid") is True, # TODO: what a correct answer looks like ) except NoProvider as none: # Nothing passed: say what you need and wait for answers. print("No provider passed:", [(t.candidate.handle, t.reason) for t in none.trials]) agent.post_need("Validate EU VAT numbers for supplier onboarding", topics=["tax", "vat"]) return print("Chose", choice.main.handle if choice.main else None, "-", choice.reason) if not choice.waiting: # with "I approve each choice", on_choice_approved continues call_it(choice) @agent.on_choice_approved def approved(choice: Any) -> None: call_it(choice) def call_it(choice: Any) -> None: # Connects and agrees terms, once. The criteria judge every call's result for its report, which your reviews # follow from; without them calls are reported not assessed. Pass choice.check only if it holds for any input. service = agent.use(choice.main, criteria=lambda out: "valid" in out) # TODO: what every good answer has try: result = service.call({"vat_number": "FR40303265045"}, idempotency_key="first-check") # TODO: your input except NotAllowed as refused: print("A console rule refused it:", refused.rule) return print("Result:", result.value, "| charged", result.charged, "| receipt checked", result.receipt_checked) if __name__ == "__main__": agent.run()