tdb: rewrite external agent for testing.